Mercurial > mplayer.hg
annotate Gui/win32/interface.c @ 19638:a3473d990fed
Better collision detection algorithm. The idea is to keep a subtitle in place
when a lower placed one disappears, thus improving readability.
As a side effect, layers are supported now.
author | eugeni |
---|---|
date | Sat, 02 Sep 2006 19:17:32 +0000 |
parents | 69b134c4caea |
children | e701a6eed5cb |
rev | line source |
---|---|
18914 | 1 /* |
2 MPlayer Gui for win32 | |
3 Copyright (c) 2003 Sascha Sommer <saschasommer@freenet.de> | |
4 Copyright (c) 2006 Erik Augustson <erik_27can@yahoo.com> | |
5 Copyright (c) 2006 Gianluigi Tiesi <sherpya@netfarm.it> | |
6 | |
7 This program is free software; you can redistribute it and/or modify | |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2 of the License, or | |
10 (at your option) any later version. | |
11 | |
12 This program is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with this program; if not, write to the Free Software | |
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA | |
20 */ | |
21 | |
22 #include <windows.h> | |
23 #include <interface.h> | |
24 #include <m_option.h> | |
25 #include <mixer.h> | |
26 #include <mp_msg.h> | |
27 #include <help_mp.h> | |
28 #include <codec-cfg.h> | |
19271
64d82a45a05d
introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
ben
parents:
19245
diff
changeset
|
29 #include <stream/stream.h> |
18914 | 30 #include <libmpdemux/demuxer.h> |
31 #include <libmpdemux/stheader.h> | |
32 #ifdef USE_DVDREAD | |
19271
64d82a45a05d
introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
ben
parents:
19245
diff
changeset
|
33 #include <stream/stream_dvd.h> |
18914 | 34 #endif |
35 #include <input/input.h> | |
36 #include <libvo/video_out.h> | |
37 #include <libao2/audio_out.h> | |
38 #include "gui.h" | |
39 #include "dialogs.h" | |
40 #include "wincfg.h" | |
41 #ifdef HAVE_LIBCDIO | |
42 #include <cdio/cdio.h> | |
43 #endif | |
44 | |
45 extern m_obj_settings_t* vo_plugin_args; | |
46 extern vo_functions_t *video_out; | |
47 extern ao_functions_t *audio_out; | |
19104
2ec2301183cd
marks several read-only string parameters which aren't modified inside the called function as const. Patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
19061
diff
changeset
|
48 extern void exit_player(const char *how); |
18914 | 49 extern char *filename; |
50 extern int abs_seek_pos; | |
51 extern float rel_seek_secs; | |
52 extern mixer_t mixer; | |
53 extern int audio_id; | |
54 extern int video_id; | |
55 extern int dvdsub_id; | |
56 extern int vobsub_id; | |
57 extern int stream_cache_size; | |
58 extern int autosync; | |
59 extern int vcd_track; | |
60 extern int dvd_title; | |
61 extern float force_fps; | |
62 extern af_cfg_t af_cfg; | |
63 int guiWinID = 0; | |
64 | |
65 char *skinName = NULL; | |
66 char *codecname = NULL; | |
67 int mplGotoTheNext = 1; | |
68 static gui_t *mygui = NULL; | |
69 static int update_subwindow(void); | |
19245 | 70 static RECT old_rect; |
19535
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
71 static DWORD style; |
18914 | 72 |
73 /* test for playlist files, no need to specify -playlist on the commandline. | |
74 * add any conceivable playlist extensions here. | |
75 * - Erik | |
76 */ | |
77 int parse_filename(char *file, play_tree_t *playtree, m_config_t *mconfig, int clear) | |
78 { | |
79 if(clear) | |
80 mygui->playlist->clear_playlist(mygui->playlist); | |
81 | |
82 if(strstr(file, ".m3u") || strstr(file, ".pls")) | |
83 { | |
84 playtree = parse_playlist_file(file); | |
85 import_playtree_playlist_into_gui(playtree, mconfig); | |
86 return 1; | |
87 } | |
88 return 0; | |
89 } | |
90 | |
91 /** | |
92 * \brief this actually creates a new list containing only one element... | |
93 */ | |
19147
2149651156bc
Compile fix, patch by Aidan Thornton % makomk # lycos P co P uk %
gpoirier
parents:
19104
diff
changeset
|
94 void gaddlist( char ***list, const char *entry) |
18914 | 95 { |
96 int i; | |
97 | |
98 if (*list) | |
99 { | |
100 for (i=0; (*list)[i]; i++) free((*list)[i]); | |
101 free(*list); | |
102 } | |
103 | |
104 *list = malloc(2 * sizeof(char **)); | |
105 (*list)[0] = gstrdup(entry); | |
106 (*list)[1] = NULL; | |
107 } | |
108 | |
19147
2149651156bc
Compile fix, patch by Aidan Thornton % makomk # lycos P co P uk %
gpoirier
parents:
19104
diff
changeset
|
109 char *gstrdup(const char *str) |
18914 | 110 { |
111 if (!str) return NULL; | |
112 return strdup(str); | |
113 } | |
114 | |
115 /** | |
116 * \brief this replaces a string starting with search by replace. | |
117 * If not found, replace is appended. | |
118 */ | |
119 void greplace(char ***list, char *search, char *replace) | |
120 { | |
121 int i = 0; | |
122 int len = (search) ? strlen(search) : 0; | |
123 | |
124 if (*list) | |
125 { | |
126 for (i = 0; (*list)[i]; i++) | |
127 { | |
128 if (search && (!strncmp((*list)[i], search, len))) | |
129 { | |
130 free((*list)[i]); | |
131 (*list)[i] = gstrdup(replace); | |
132 return; | |
133 } | |
134 } | |
135 *list = realloc(*list, (i + 2) * sizeof(char *)); | |
136 } | |
137 else | |
138 *list = malloc(2 * sizeof(char *)); | |
139 | |
140 (*list)[i] = gstrdup(replace); | |
141 (*list)[i + 1] = NULL; | |
142 } | |
143 | |
144 /* this function gets called by the gui to update mplayer */ | |
145 static void guiSetEvent(int event) | |
146 { | |
147 switch(event) | |
148 { | |
149 case evPlay: | |
150 case evPlaySwitchToPause: | |
151 mplPlay(); | |
152 break; | |
153 case evPause: | |
154 mplPause(); | |
155 break; | |
156 #ifdef USE_DVDREAD | |
157 case evPlayDVD: | |
158 { | |
159 static char dvdname[MAX_PATH]; | |
160 guiIntfStruct.DVD.current_title = dvd_title; | |
161 guiIntfStruct.DVD.current_chapter = dvd_chapter; | |
162 guiIntfStruct.DVD.current_angle = dvd_angle; | |
163 guiIntfStruct.DiskChanged = 1; | |
164 | |
165 mplSetFileName(NULL, dvd_device, STREAMTYPE_DVD); | |
166 guiIntfStruct.Title = guiIntfStruct.DVD.current_title; | |
167 guiIntfStruct.Chapter = guiIntfStruct.DVD.current_chapter; | |
168 guiIntfStruct.Angle = guiIntfStruct.DVD.current_angle; | |
169 | |
170 dvdname[0] = 0; | |
171 strcat(dvdname, "DVD Movie"); | |
172 GetVolumeInformation(dvd_device, dvdname, MAX_PATH, NULL, NULL, NULL, NULL, 0); | |
173 capitalize(dvdname); | |
174 mp_msg(MSGT_GPLAYER, MSGL_V, "Opening DVD %s -> %s\n", dvd_device, dvdname); | |
175 guiGetEvent(guiSetParameters, (char *) STREAMTYPE_DVD); | |
176 mygui->playlist->clear_playlist(mygui->playlist); | |
177 mygui->playlist->add_track(mygui->playlist, filename, NULL, dvdname, 0); | |
178 mygui->startplay(mygui); | |
179 break; | |
180 } | |
181 #endif | |
182 #ifdef HAVE_LIBCDIO | |
183 case evPlayCD: | |
184 { | |
185 int i; | |
186 char track[10]; | |
187 char trackname[10]; | |
188 CdIo_t *p_cdio = cdio_open(NULL, DRIVER_UNKNOWN); | |
189 track_t i_tracks; | |
190 | |
191 if(p_cdio == NULL) printf("Couldn't find a driver.\n"); | |
192 i_tracks = cdio_get_num_tracks(p_cdio); | |
193 | |
194 mygui->playlist->clear_playlist(mygui->playlist); | |
195 for(i=0;i<i_tracks;i++) | |
196 { | |
197 sprintf(track, "cdda://%d", i+1); | |
198 sprintf(trackname, "Track %d", i+1); | |
199 mygui->playlist->add_track(mygui->playlist, track, NULL, trackname, 0); | |
200 } | |
201 cdio_destroy(p_cdio); | |
202 mygui->startplay(mygui); | |
203 break; | |
204 } | |
205 #endif | |
206 case evFullScreen: | |
207 mp_input_queue_cmd(mp_input_parse_cmd("vo_fullscreen")); | |
208 break; | |
209 case evExit: | |
210 { | |
211 /* We are asking mplayer to exit, later it will ask us after uninit is made | |
212 this should be the only safe way to quit */ | |
213 mygui->activewidget = NULL; | |
214 mp_input_queue_cmd(mp_input_parse_cmd("quit")); | |
215 break; | |
216 } | |
217 case evStop: | |
218 if(guiIntfStruct.Playing) | |
219 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
220 break; | |
221 case evSetMoviePosition: | |
222 { | |
223 rel_seek_secs = guiIntfStruct.Position / 100.0f; | |
224 abs_seek_pos = 3; | |
225 break; | |
226 } | |
227 case evForward10sec: | |
228 { | |
229 rel_seek_secs = 10.0f; | |
230 abs_seek_pos = 0; | |
231 break; | |
232 } | |
233 case evBackward10sec: | |
234 { | |
235 rel_seek_secs = -10.0f; | |
236 abs_seek_pos = 0; | |
237 break; | |
238 } | |
239 case evSetBalance: | |
240 case evSetVolume: | |
241 { | |
242 float l,r; | |
243 | |
18953
b83cefcd7e41
crash fix when clicking on volume sliders when in stop state.
vayne
parents:
18947
diff
changeset
|
244 if (guiIntfStruct.Playing == 0) |
b83cefcd7e41
crash fix when clicking on volume sliders when in stop state.
vayne
parents:
18947
diff
changeset
|
245 break; |
b83cefcd7e41
crash fix when clicking on volume sliders when in stop state.
vayne
parents:
18947
diff
changeset
|
246 |
18914 | 247 if (guiIntfStruct.Balance == 50.0f) |
248 mixer_setvolume(&mixer, guiIntfStruct.Volume, guiIntfStruct.Volume); | |
249 | |
250 l = guiIntfStruct.Volume * ((100.0f - guiIntfStruct.Balance) / 50.0f); | |
251 r = guiIntfStruct.Volume * ((guiIntfStruct.Balance) / 50.0f); | |
252 | |
253 if (l > guiIntfStruct.Volume) l=guiIntfStruct.Volume; | |
254 if (r > guiIntfStruct.Volume) r=guiIntfStruct.Volume; | |
255 mixer_setvolume(&mixer, l, r); | |
256 /* Check for balance support on mixer - there is a better way ?? */ | |
257 if (r != l) | |
258 { | |
259 mixer_getvolume(&mixer, &l, &r); | |
260 if (r == l) | |
261 { | |
262 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Mixer doesn't support balanced audio\n"); | |
263 mixer_setvolume(&mixer, guiIntfStruct.Volume, guiIntfStruct.Volume); | |
264 guiIntfStruct.Balance = 50.0f; | |
265 } | |
266 } | |
267 break; | |
268 } | |
269 case evMute: | |
270 { | |
19061
86350b4b8203
drops casts from void * on malloc/calloc from the gui code
reynaldo
parents:
18953
diff
changeset
|
271 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); |
18914 | 272 cmd->id=MP_CMD_MUTE; |
273 cmd->name=strdup("mute"); | |
274 mp_input_queue_cmd(cmd); | |
275 break; | |
276 } | |
277 case evDropFile: | |
278 case evLoadPlay: | |
279 { | |
280 mplSetFileName(NULL, filename, STREAMTYPE_FILE); | |
281 guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
282 update_playlistwindow(); | |
283 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
284 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
285 break; | |
286 } | |
287 case evNext: | |
288 mplNext(); | |
289 break; | |
290 case evPrev: | |
291 mplPrev(); | |
292 break; | |
293 } | |
294 } | |
295 | |
296 void mplPlay( void ) | |
297 { | |
298 if((!guiIntfStruct.Filename ) || (guiIntfStruct.Filename[0] == 0)) | |
299 return; | |
300 | |
301 if(guiIntfStruct.Playing > 0) | |
302 { | |
303 mplPause(); | |
304 return; | |
305 } | |
306 guiIntfStruct.NewPlay = 1; | |
307 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
308 } | |
309 | |
310 void mplPause( void ) | |
311 { | |
312 if(!guiIntfStruct.Playing) return; | |
313 | |
314 if(guiIntfStruct.Playing == 1) | |
315 { | |
19061
86350b4b8203
drops casts from void * on malloc/calloc from the gui code
reynaldo
parents:
18953
diff
changeset
|
316 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); |
18914 | 317 cmd->id=MP_CMD_PAUSE; |
318 cmd->name=strdup("pause"); | |
319 mp_input_queue_cmd(cmd); | |
320 } else guiIntfStruct.Playing = 1; | |
321 } | |
322 | |
323 void mplNext(void) | |
324 { | |
325 if(guiIntfStruct.Playing == 2) return; | |
326 switch(guiIntfStruct.StreamType) | |
327 { | |
328 #ifdef USE_DVDREAD | |
329 case STREAMTYPE_DVD: | |
330 if(guiIntfStruct.DVD.current_chapter == (guiIntfStruct.DVD.chapters - 1)) | |
331 return; | |
332 guiIntfStruct.DVD.current_chapter++; | |
333 break; | |
334 #endif | |
335 default: | |
336 if(mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
337 return; | |
338 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, | |
339 STREAMTYPE_STREAM); | |
340 break; | |
341 } | |
342 mplGotoTheNext = 0; | |
343 mygui->startplay(mygui); | |
344 } | |
345 | |
346 void mplPrev(void) | |
347 { | |
348 if(guiIntfStruct.Playing == 2) return; | |
349 switch(guiIntfStruct.StreamType) | |
350 { | |
351 #ifdef USE_DVDREAD | |
352 case STREAMTYPE_DVD: | |
353 if(guiIntfStruct.DVD.current_chapter == 1) | |
354 return; | |
355 guiIntfStruct.DVD.current_chapter--; | |
356 break; | |
357 #endif | |
358 default: | |
359 if(mygui->playlist->current == 0) | |
360 return; | |
361 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)--]->filename, | |
362 STREAMTYPE_STREAM); | |
363 break; | |
364 } | |
365 mplGotoTheNext = 0; | |
366 mygui->startplay(mygui); | |
367 } | |
368 | |
369 void mplEnd( void ) | |
370 { | |
371 if(!mplGotoTheNext && guiIntfStruct.Playing) | |
372 { | |
373 mplGotoTheNext = 1; | |
374 return; | |
375 } | |
376 | |
377 if(mplGotoTheNext && guiIntfStruct.Playing && | |
378 (mygui->playlist->current < (mygui->playlist->trackcount - 1)) && | |
379 guiIntfStruct.StreamType != STREAMTYPE_DVD && | |
380 guiIntfStruct.StreamType != STREAMTYPE_DVDNAV) | |
381 { | |
382 /* we've finished this file, reset the aspect */ | |
383 if(movie_aspect >= 0) | |
384 movie_aspect = -1; | |
385 | |
386 mplGotoTheNext = guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
387 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, STREAMTYPE_STREAM); | |
388 //sprintf(guiIntfStruct.Filename, mygui->playlist->tracks[(mygui->playlist->current)++]->filename); | |
389 } | |
390 | |
391 if(guiIntfStruct.FilenameChanged && guiIntfStruct.NewPlay) | |
392 return; | |
393 | |
394 guiIntfStruct.TimeSec = 0; | |
395 guiIntfStruct.Position = 0; | |
396 guiIntfStruct.AudioType = 0; | |
397 | |
398 #ifdef USE_DVDREAD | |
399 guiIntfStruct.DVD.current_title = 1; | |
400 guiIntfStruct.DVD.current_chapter = 1; | |
401 guiIntfStruct.DVD.current_angle = 1; | |
402 #endif | |
403 | |
404 if (mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
405 mygui->playlist->current = 0; | |
406 | |
19408 | 407 fullscreen = 0; |
19535
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
408 if(style == WS_VISIBLE | WS_POPUP) |
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
409 { |
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
410 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; |
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
411 SetWindowLong(mygui->subwindow, GWL_STYLE, style); |
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
412 } |
18914 | 413 guiGetEvent(guiCEvent, (void *) guiSetStop); |
414 } | |
415 | |
416 void mplSetFileName(char *dir, char *name, int type) | |
417 { | |
418 if(!name) return; | |
419 if(!dir) | |
420 guiSetFilename(guiIntfStruct.Filename, name) | |
421 else | |
422 guiSetDF(guiIntfStruct.Filename, dir, name); | |
423 | |
424 guiIntfStruct.StreamType = type; | |
425 free((void **) &guiIntfStruct.AudioFile); | |
426 free((void **) &guiIntfStruct.Subtitlename); | |
427 } | |
428 | |
429 static DWORD WINAPI GuiThread(void) | |
430 { | |
431 MSG msg; | |
432 | |
433 if(!skinName) skinName = strdup("Blue"); | |
434 if(!mygui) mygui = create_gui(get_path("skins"), skinName, guiSetEvent); | |
435 if(!mygui) exit_player("Unable to load gui"); | |
436 | |
437 if(autosync && autosync != gtkAutoSync) | |
438 { | |
439 gtkAutoSyncOn = 1; | |
440 gtkAutoSync = autosync; | |
441 } | |
442 | |
443 while(mygui) | |
444 { | |
445 GetMessage(&msg, NULL, 0, 0); | |
446 TranslateMessage(&msg); | |
447 DispatchMessage(&msg); | |
448 } | |
449 fprintf(stderr, "[GUI] Gui Thread Terminated\n"); | |
450 fflush(stderr); | |
451 return 0; | |
452 } | |
453 | |
454 void guiInit(void) | |
455 { | |
456 memset(&guiIntfStruct, 0, sizeof(guiIntfStruct)); | |
457 /* Create The gui thread */ | |
458 if (!mygui) | |
459 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Creating GUI Thread 0x%04x\n", | |
460 (int) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) GuiThread, NULL, 0, NULL)); | |
461 | |
462 /* Wait until the gui is created */ | |
463 while(!mygui) Sleep(100); | |
464 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Gui Thread started\n"); | |
465 } | |
466 | |
467 void guiDone(void) | |
468 { | |
469 if(mygui) | |
470 { | |
471 fprintf(stderr, "[GUI] Closed by main mplayer window\n"); | |
472 fflush(stderr); | |
473 mygui->uninit(mygui); | |
474 free(mygui); | |
475 TerminateThread(GuiThread, 0); | |
476 mygui = NULL; | |
477 } | |
478 /* Remove tray icon */ | |
479 Shell_NotifyIcon(NIM_DELETE, &nid); | |
480 cfg_write(); | |
481 } | |
482 | |
483 static void add_vop(char * str) | |
484 { | |
485 mp_msg(MSGT_GPLAYER, MSGL_STATUS, MSGTR_AddingVideoFilter, str); | |
486 if (vo_plugin_args) | |
487 { | |
488 int i = 0; | |
489 while (vo_plugin_args[i].name) | |
490 if (!strcmp(vo_plugin_args[i++].name, str)) | |
491 { | |
492 i = -1; | |
493 break; | |
494 } | |
495 if (i != -1) | |
496 { | |
497 vo_plugin_args = realloc(vo_plugin_args, (i + 2) * sizeof(m_obj_settings_t)); | |
498 vo_plugin_args[i].name = strdup(str); | |
499 vo_plugin_args[i].attribs = NULL; | |
500 vo_plugin_args[i + 1].name = NULL; | |
501 } | |
502 } | |
503 else | |
504 { | |
505 vo_plugin_args = malloc(2 * sizeof(m_obj_settings_t)); | |
506 vo_plugin_args[0].name = strdup(str); | |
507 vo_plugin_args[0].attribs = NULL; | |
508 vo_plugin_args[1].name = NULL; | |
509 } | |
510 } | |
511 | |
512 static void remove_vop(char * str) | |
513 { | |
514 int n = 0; | |
515 if (!vo_plugin_args ) return; | |
516 | |
517 mp_msg(MSGT_GPLAYER,MSGL_STATUS, MSGTR_RemovingVideoFilter, str); | |
518 | |
519 while (vo_plugin_args[n++].name); | |
520 n--; | |
521 if ( n > -1 ) | |
522 { | |
523 int i = 0, m = -1; | |
524 while (vo_plugin_args[i].name) | |
525 if (!strcmp(vo_plugin_args[i++].name, str)) | |
526 { | |
527 m = i - 1; | |
528 break; | |
529 } | |
530 i--; | |
531 if (m > -1) | |
532 { | |
533 if (n == 1) | |
534 { | |
535 free(vo_plugin_args[0].name); | |
536 free(vo_plugin_args[0].attribs); | |
537 free(vo_plugin_args); | |
538 vo_plugin_args=NULL; | |
539 } | |
540 else | |
541 { | |
542 free(vo_plugin_args[i].name); | |
543 free(vo_plugin_args[i].attribs); | |
544 memcpy(&vo_plugin_args[i], &vo_plugin_args[i + 1], (n - i) * sizeof(m_obj_settings_t)); | |
545 } | |
546 } | |
547 } | |
548 } | |
549 | |
550 /* this function gets called by mplayer to update the gui */ | |
551 int guiGetEvent(int type, char *arg) | |
552 { | |
553 if(!mygui || !mygui->skin) return 0; | |
554 | |
555 stream_t *stream = (stream_t *) arg; | |
556 #ifdef USE_DVDREAD | |
557 dvd_priv_t *dvdp = (dvd_priv_t *) arg; | |
558 #endif | |
559 | |
560 switch (type) | |
561 { | |
562 case guiSetFileFormat: | |
563 guiIntfStruct.FileFormat = (int) arg; | |
564 break; | |
565 case guiSetParameters: | |
566 { | |
567 guiGetEvent(guiSetDefaults, NULL); | |
568 guiIntfStruct.DiskChanged = 0; | |
569 guiIntfStruct.FilenameChanged = 0; | |
570 guiIntfStruct.NewPlay = 0; | |
571 switch(guiIntfStruct.StreamType) | |
572 { | |
573 case STREAMTYPE_PLAYLIST: | |
574 break; | |
575 #ifdef USE_DVDREAD | |
576 case STREAMTYPE_DVD: | |
577 { | |
578 char tmp[512]; | |
579 dvd_title = guiIntfStruct.DVD.current_title; | |
580 dvd_chapter = guiIntfStruct.DVD.current_chapter; | |
581 dvd_angle = guiIntfStruct.DVD.current_angle; | |
582 sprintf(tmp,"dvd://%d", guiIntfStruct.Title); | |
583 guiSetFilename(guiIntfStruct.Filename, tmp); | |
584 break; | |
585 } | |
586 #endif | |
587 } | |
588 if(guiIntfStruct.Filename) | |
589 filename = strdup(guiIntfStruct.Filename); | |
590 else if(filename) | |
591 strcpy(guiIntfStruct.Filename, filename); | |
592 break; | |
593 } | |
594 case guiSetAudioOnly: | |
595 { | |
596 guiIntfStruct.AudioOnly = (int) arg; | |
597 if(IsWindowVisible(mygui->subwindow)) | |
598 ShowWindow(mygui->subwindow, SW_HIDE); | |
599 break; | |
600 } | |
601 case guiSetDemuxer: | |
602 guiIntfStruct.demuxer = (void *) arg; | |
603 break; | |
604 case guiSetValues: | |
605 { | |
606 guiIntfStruct.sh_video = arg; | |
607 if (arg) | |
608 { | |
609 sh_video_t *sh = (sh_video_t *)arg; | |
610 codecname = sh->codec->name; | |
611 guiIntfStruct.FPS = sh->fps; | |
612 | |
613 /* we have video, show the subwindow */ | |
614 if(!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) | |
615 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
616 if(WinID == -1) | |
617 update_subwindow(); | |
618 | |
619 } | |
620 break; | |
621 } | |
622 case guiSetShVideo: | |
623 { | |
624 guiIntfStruct.MovieWidth = vo_dwidth; | |
625 guiIntfStruct.MovieHeight = vo_dheight; | |
626 | |
627 sub_aspect = (float)guiIntfStruct.MovieWidth/guiIntfStruct.MovieHeight; | |
628 if(WinID != -1) | |
629 update_subwindow(); | |
630 break; | |
631 } | |
632 case guiSetStream: | |
633 { | |
634 guiIntfStruct.StreamType = stream->type; | |
635 switch(stream->type) | |
636 { | |
637 #ifdef USE_DVDREAD | |
638 case STREAMTYPE_DVD: | |
639 guiGetEvent(guiSetDVD, (char *) stream->priv); | |
640 break; | |
641 #endif | |
642 } | |
643 break; | |
644 } | |
645 #ifdef USE_DVDREAD | |
646 case guiSetDVD: | |
647 { | |
648 guiIntfStruct.DVD.titles = dvdp->vmg_file->tt_srpt->nr_of_srpts; | |
649 guiIntfStruct.DVD.chapters = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_ptts; | |
650 guiIntfStruct.DVD.angles = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_angles; | |
651 guiIntfStruct.DVD.nr_of_audio_channels = dvdp->nr_of_channels; | |
652 memcpy(guiIntfStruct.DVD.audio_streams, dvdp->audio_streams, sizeof(dvdp->audio_streams)); | |
653 guiIntfStruct.DVD.nr_of_subtitles = dvdp->nr_of_subtitles; | |
654 memcpy(guiIntfStruct.DVD.subtitles, dvdp->subtitles, sizeof(dvdp->subtitles)); | |
655 guiIntfStruct.DVD.current_title = dvd_title + 1; | |
656 guiIntfStruct.DVD.current_chapter = dvd_chapter + 1; | |
657 guiIntfStruct.DVD.current_angle = dvd_angle + 1; | |
658 guiIntfStruct.Track = dvd_title + 1; | |
659 break; | |
660 } | |
661 #endif | |
662 case guiReDraw: | |
663 mygui->updatedisplay(mygui, mygui->mainwindow); | |
664 break; | |
665 case guiSetAfilter: | |
666 guiIntfStruct.afilter = (void *) arg; | |
667 break; | |
668 case guiCEvent: | |
669 { | |
670 guiIntfStruct.Playing = (int) arg; | |
671 switch (guiIntfStruct.Playing) | |
672 { | |
673 case guiSetPlay: | |
674 { | |
675 guiIntfStruct.Playing = 1; | |
676 break; | |
677 } | |
678 case guiSetStop: | |
679 { | |
680 guiIntfStruct.Playing = 0; | |
681 if(movie_aspect >= 0) | |
682 movie_aspect = -1; | |
683 update_subwindow(); | |
684 break; | |
685 } | |
686 case guiSetPause: | |
687 guiIntfStruct.Playing = 2; | |
688 break; | |
689 } | |
690 break; | |
691 } | |
692 case guiIEvent: | |
693 { | |
694 mp_msg(MSGT_GPLAYER,MSGL_V, "cmd: %d\n", (int) arg); | |
695 /* MPlayer asks us to quit */ | |
696 switch((int) arg) | |
697 { | |
698 case MP_CMD_GUI_FULLSCREEN: | |
699 { | |
700 if(!guiIntfStruct.sh_video) break; | |
701 | |
19408 | 702 if(!sub_window) |
19245 | 703 { |
704 video_out->control(VOCTRL_FULLSCREEN, 0); | |
18914 | 705 break; |
19245 | 706 } |
18914 | 707 |
19408 | 708 if(!fullscreen && IsWindowVisible(mygui->subwindow) && !IsIconic(mygui->subwindow)) |
19245 | 709 GetWindowRect(mygui->subwindow, &old_rect); |
710 | |
711 if(fullscreen) | |
18914 | 712 { |
19408 | 713 fullscreen = 0; |
714 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
18914 | 715 } else { |
19408 | 716 fullscreen = 1; |
717 style = WS_VISIBLE | WS_POPUP; | |
18914 | 718 } |
19408 | 719 SetWindowLong(mygui->subwindow, GWL_STYLE, style); |
19245 | 720 mpcodecs_config_vo(guiIntfStruct.sh_video, guiIntfStruct.MovieWidth, |
721 guiIntfStruct.MovieHeight, 0); | |
18914 | 722 break; |
723 } | |
724 case MP_CMD_QUIT: | |
725 { | |
726 mygui->uninit(mygui); | |
727 free(mygui); | |
728 mygui = NULL; | |
729 exit_player("Done"); | |
730 return 0; | |
731 } | |
732 case MP_CMD_GUI_STOP: | |
733 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
734 break; | |
735 case MP_CMD_GUI_PLAY: | |
736 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
737 break; | |
738 case MP_CMD_GUI_SKINBROWSER: | |
19245 | 739 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 740 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_SKINBROWSER, 0); |
741 break; | |
742 case MP_CMD_GUI_PLAYLIST: | |
19245 | 743 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 744 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_PLAYLIST, 0); |
745 break; | |
746 case MP_CMD_GUI_PREFERENCES: | |
19245 | 747 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 748 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_PREFS, 0); |
749 break; | |
750 case MP_CMD_GUI_LOADFILE: | |
19245 | 751 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 752 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) IDFILE_OPEN, 0); |
753 break; | |
754 #ifdef USE_SUB | |
755 case MP_CMD_GUI_LOADSUBTITLE: | |
19245 | 756 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 757 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) IDSUBTITLE_OPEN, 0); |
758 break; | |
759 #endif | |
760 default: | |
761 break; | |
762 } | |
763 break; | |
764 } | |
765 case guiSetFileName: | |
766 if (arg) guiIntfStruct.Filename = (char *) arg; | |
767 break; | |
768 case guiSetDefaults: | |
769 { | |
770 audio_id = -1; | |
771 video_id = -1; | |
772 dvdsub_id = -1; | |
773 vobsub_id = -1; | |
774 stream_cache_size = -1; | |
775 autosync = 0; | |
776 vcd_track = 0; | |
777 dvd_title = 0; | |
778 force_fps = 0; | |
779 if(!mygui->playlist->tracks) return 0; | |
780 filename = guiIntfStruct.Filename = mygui->playlist->tracks[mygui->playlist->current]->filename; | |
781 guiIntfStruct.Track = mygui->playlist->current + 1; | |
782 if(gtkAONorm) greplace(&af_cfg.list, "volnorm", "volnorm"); | |
783 if(gtkAOExtraStereo) | |
784 { | |
785 char *name = malloc(12 + 20 + 1); | |
786 snprintf(name, 12 + 20, "extrastereo=%f", gtkAOExtraStereoMul); | |
787 name[12 + 20] = 0; | |
788 greplace(&af_cfg.list, "extrastereo", name); | |
789 free(name); | |
790 } | |
791 if(gtkCacheOn) stream_cache_size = gtkCacheSize; | |
792 if(gtkAutoSyncOn) autosync = gtkAutoSync; | |
793 break; | |
794 } | |
795 case guiSetVolume: | |
796 { | |
797 if(audio_out) | |
798 { | |
799 /* Some audio_out drivers do not support balance e.g. dsound */ | |
800 /* FIXME this algo is not correct */ | |
801 float l, r; | |
802 mixer_getvolume(&mixer, &l, &r); | |
803 guiIntfStruct.Volume = (r > l ? r : l); /* max(r,l) */ | |
804 if (r != l) | |
805 guiIntfStruct.Balance = ((r-l) + 100.0f) * 0.5f; | |
806 else | |
807 guiIntfStruct.Balance = 50.0f; | |
808 } | |
809 break; | |
810 } | |
811 default: | |
812 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[GUI] GOT UNHANDLED EVENT %i\n", type); | |
813 } | |
814 return 0; | |
815 } | |
816 | |
817 /* This function adds/inserts one file into the gui playlist */ | |
818 int import_file_into_gui(char *pathname, int insert) | |
819 { | |
820 char filename[MAX_PATH]; | |
821 char *filepart = filename; | |
822 | |
823 if (strstr(pathname, "://")) | |
824 { | |
825 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding special %s\n", pathname); | |
826 mygui->playlist->add_track(mygui->playlist, pathname, NULL, NULL, 0); | |
827 return 1; | |
828 } | |
829 if (GetFullPathName(pathname, MAX_PATH, filename, &filepart)) | |
830 { | |
831 if (!(GetFileAttributes(filename) & FILE_ATTRIBUTE_DIRECTORY)) | |
832 { | |
833 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding filename: %s - fullpath: %s\n", filepart, filename); | |
834 mygui->playlist->add_track(mygui->playlist, filename, NULL, filepart, 0); | |
835 return 1; | |
836 } | |
837 else | |
838 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Cannot add %s\n", filename); | |
839 } | |
840 | |
841 return 0; | |
842 } | |
843 | |
844 /* This function imports the initial playtree (based on cmd-line files) into the gui playlist | |
845 by either: | |
846 - overwriting gui pl (enqueue=0) */ | |
847 | |
848 int import_initial_playtree_into_gui(play_tree_t *my_playtree, m_config_t *config, int enqueue) | |
849 { | |
850 play_tree_iter_t *my_pt_iter = NULL; | |
851 int result = 0; | |
852 | |
853 if(!mygui) guiInit(); | |
854 | |
855 if((my_pt_iter = pt_iter_create(&my_playtree, config))) | |
856 { | |
857 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) | |
858 { | |
859 if (parse_filename(filename, my_playtree, config, 0)) | |
860 result = 1; | |
861 else if (import_file_into_gui(filename, 0)) /* Add it to end of list */ | |
862 result = 1; | |
863 } | |
864 } | |
865 mplGotoTheNext = 1; | |
866 | |
867 if (result) | |
868 { | |
869 mygui->playlist->current = 0; | |
870 filename = mygui->playlist->tracks[0]->filename; | |
871 } | |
872 return result; | |
873 } | |
874 | |
875 /* This function imports and inserts an playtree, that is created "on the fly", for example by | |
876 parsing some MOV-Reference-File; or by loading an playlist with "File Open" | |
877 The file which contained the playlist is thereby replaced with it's contents. */ | |
878 | |
879 int import_playtree_playlist_into_gui(play_tree_t *my_playtree, m_config_t *config) | |
880 { | |
881 play_tree_iter_t *my_pt_iter = NULL; | |
882 int result = 0; | |
883 | |
884 if((my_pt_iter = pt_iter_create(&my_playtree, config))) | |
885 { | |
886 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) | |
887 if (import_file_into_gui(filename, 1)) /* insert it into the list and set plCurrent = new item */ | |
888 result = 1; | |
889 pt_iter_destroy(&my_pt_iter); | |
890 } | |
891 filename = NULL; | |
892 return result; | |
893 } | |
894 | |
895 inline void gtkMessageBox(int type, const char *str) | |
896 { | |
897 if (type & GTK_MB_FATAL) | |
898 MessageBox(NULL, str, "MPlayer GUI for Windows Error", MB_OK | MB_ICONERROR); | |
899 | |
900 fprintf(stderr, "[GUI] MessageBox: %s\n", str); | |
901 fflush(stderr); | |
902 } | |
903 | |
904 void guiMessageBox(int level, char *str) | |
905 { | |
906 switch(level) | |
907 { | |
908 case MSGL_FATAL: | |
909 gtkMessageBox(GTK_MB_FATAL | GTK_MB_SIMPLE, str); | |
910 break; | |
911 case MSGL_ERR: | |
912 gtkMessageBox(GTK_MB_ERROR | GTK_MB_SIMPLE, str); | |
913 break; | |
914 } | |
915 } | |
916 | |
917 static int update_subwindow(void) | |
918 { | |
919 int x,y; | |
920 RECT rd; | |
921 WINDOWPOS wp; | |
922 | |
18947
06ab2099c10e
OpenGL outputs actually support WinID, not to mention that showing the option
reimar
parents:
18914
diff
changeset
|
923 if(!sub_window) |
18914 | 924 { |
925 WinID = -1; // so far only directx supports WinID in windows | |
926 | |
927 if(IsWindowVisible(mygui->subwindow) && guiIntfStruct.sh_video && guiIntfStruct.Playing) | |
928 { | |
929 ShowWindow(mygui->subwindow, SW_HIDE); | |
930 return 0; | |
931 } | |
932 else if(guiIntfStruct.AudioOnly) | |
933 return 0; | |
934 else ShowWindow(mygui->subwindow, SW_SHOW); | |
935 } | |
936 | |
937 /* we've come out of fullscreen at the end of file */ | |
938 if((!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) && !guiIntfStruct.AudioOnly) | |
939 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
940 | |
941 /* get our current window coordinates */ | |
19535
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
942 GetWindowRect(mygui->subwindow, &rd); |
19245 | 943 |
18914 | 944 x = rd.left; |
945 y = rd.top; | |
946 | |
19535
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
947 /* restore sub window position when coming out of fullscreen */ |
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
948 if(x <= 0) x = old_rect.left; |
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
949 if(y <= 0) y = old_rect.top; |
69b134c4caea
Further fullscreen switching improvements. Fixes sub window position bug when exiting a file from fullscreen. Fixes sub window position when switching between windows and fullscreen modes.
vayne
parents:
19408
diff
changeset
|
950 |
18914 | 951 if(!guiIntfStruct.Playing) |
952 { | |
953 window *desc = NULL; | |
954 int i; | |
955 | |
956 for (i=0; i<mygui->skin->windowcount; i++) | |
957 if(mygui->skin->windows[i]->type == wiSub) | |
958 desc = mygui->skin->windows[i]; | |
959 | |
960 rd.right = rd.left+desc->base->bitmap[0]->width; | |
961 rd.bottom = rd.top+desc->base->bitmap[0]->height; | |
962 sub_aspect = (float)(rd.right-rd.left)/(rd.bottom-rd.top); | |
963 } | |
964 else | |
965 { | |
966 rd.right = rd.left+guiIntfStruct.MovieWidth; | |
967 rd.bottom = rd.top+guiIntfStruct.MovieHeight; | |
968 | |
969 if (movie_aspect > 0.0) // forced aspect from the cmdline | |
970 sub_aspect = movie_aspect; | |
971 } | |
972 | |
19245 | 973 |
18914 | 974 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0); |
19245 | 975 SetWindowPos(mygui->subwindow, 0, x, y, rd.right-rd.left, rd.bottom-rd.top, SWP_NOOWNERZORDER); |
18914 | 976 |
977 wp.hwnd = mygui->subwindow; | |
978 wp.x = rd.left; | |
979 wp.y = rd.top; | |
980 wp.cx = rd.right-rd.left; | |
981 wp.cy = rd.bottom-rd.top; | |
982 wp.flags = SWP_NOOWNERZORDER | SWP_SHOWWINDOW; | |
983 | |
984 /* erase the bitmap image if there's video */ | |
985 if(guiIntfStruct.Playing != 0 && guiIntfStruct.sh_video) | |
986 SendMessage(mygui->subwindow, WM_ERASEBKGND, (WPARAM)GetDC(mygui->subwindow), 0); | |
987 | |
988 /* reset the window aspect */ | |
989 SendMessage(mygui->subwindow, WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp); | |
990 return 0; | |
991 } | |
992 | |
993 void guiEventHandling(void) {} |