Mercurial > mplayer.hg
annotate Gui/win32/gui.c @ 19616:98204aa21b0a
Update with current status.
author | diego |
---|---|
date | Fri, 01 Sep 2006 16:13:14 +0000 |
parents | a894b3a3d28c |
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 <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <ctype.h> | |
25 #include <fcntl.h> | |
26 #include <windows.h> | |
27 #include <windowsx.h> | |
28 #include <shlobj.h> | |
29 #include <version.h> | |
30 #include <mplayer.h> | |
31 #include <mp_msg.h> | |
32 #include <help_mp.h> | |
33 #include <cpudetect.h> | |
34 #include <input/input.h> | |
35 #include <input/mouse.h> | |
36 #include <osdep/keycodes.h> | |
19271
64d82a45a05d
introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
ben
parents:
19245
diff
changeset
|
37 #include <stream/stream.h> |
18914 | 38 #include <libvo/video_out.h> |
39 #include <interface.h> | |
40 #include "gui.h" | |
41 #include "wincfg.h" | |
42 #include "dialogs.h" | |
43 | |
18930
d7ab6268e3ea
Some older MinGW versions have a broken INVALID_FILE_ATTRIBUTES, so hack around that for now.
reimar
parents:
18914
diff
changeset
|
44 // HACK around bug in old mingw |
d7ab6268e3ea
Some older MinGW versions have a broken INVALID_FILE_ATTRIBUTES, so hack around that for now.
reimar
parents:
18914
diff
changeset
|
45 #undef INVALID_FILE_ATTRIBUTES |
d7ab6268e3ea
Some older MinGW versions have a broken INVALID_FILE_ATTRIBUTES, so hack around that for now.
reimar
parents:
18914
diff
changeset
|
46 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) |
d7ab6268e3ea
Some older MinGW versions have a broken INVALID_FILE_ATTRIBUTES, so hack around that for now.
reimar
parents:
18914
diff
changeset
|
47 |
18914 | 48 #ifndef WM_XBUTTONDOWN |
49 # define WM_XBUTTONDOWN 0x020B | |
50 # define WM_XBUTTONUP 0x020C | |
51 # define WM_XBUTTONDBLCLK 0x020D | |
52 #endif | |
53 | |
54 #define MP_TITLE "MPlayer " VERSION " (C) 2000-2006 MPlayer Team" | |
55 | |
56 /* Globals / Externs */ | |
57 extern void renderinfobox(skin_t *skin, window_priv_t *priv); | |
58 extern void renderwidget(skin_t *skin, image *dest, widget *item, int state); | |
59 extern void mplayer_put_key(int code); | |
60 extern int WinID; | |
61 float sub_aspect; | |
62 | |
63 DWORD oldtime; | |
64 NOTIFYICONDATA nid; | |
65 int console_state = 0; | |
66 | |
19570
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
67 static HBRUSH colorbrush = NULL; //Handle to colorkey brush |
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
68 static COLORREF windowcolor = RGB(255,0,255); //Windowcolor == colorkey |
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
69 |
18914 | 70 void console_toggle(void) |
71 { | |
72 if (console_state) | |
73 { | |
74 FreeConsole(); | |
75 console = 0; | |
76 console_state = 0; | |
77 } | |
78 else | |
79 { | |
80 /* This code comes from: http://dslweb.nwnexus.com/~ast/dload/guicon.htm */ | |
81 CONSOLE_SCREEN_BUFFER_INFO coninfo; | |
82 FILE *fp; | |
83 HWND hwnd = NULL; | |
84 console = 1; | |
85 AllocConsole(); | |
86 SetConsoleTitle(MP_TITLE); | |
87 | |
88 /* disable the close button for now */ | |
89 while (!hwnd) | |
90 { | |
91 hwnd = FindWindow(NULL, MP_TITLE); | |
92 Sleep(100); | |
93 } | |
94 DeleteMenu(GetSystemMenu(hwnd, 0), SC_CLOSE, MF_BYCOMMAND); | |
95 | |
96 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); | |
97 coninfo.dwSize.Y = 1000; | |
98 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); | |
99 fp = freopen("con", "w", stdout); | |
100 *stdout = *fp; | |
101 setvbuf(stdout, NULL, _IONBF, 0); | |
102 fp = freopen("con", "r", stdin); | |
103 *stdin = *fp; | |
104 setvbuf(stdin, NULL, _IONBF, 0); | |
105 fp = freopen("con", "w", stdout); | |
106 *stderr = *fp; | |
107 setvbuf(stderr, NULL, _IONBF, 0); | |
108 mp_msg(MSGT_CPLAYER, MSGL_INFO, "%s\n", MP_TITLE); | |
109 GetCpuCaps(&gCpuCaps); | |
110 #if defined(ARCH_X86) || defined(ARCH_X86_64) | |
111 mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n", | |
112 gCpuCaps.hasMMX, gCpuCaps.hasMMX2, | |
113 gCpuCaps.has3DNow, gCpuCaps.has3DNowExt, | |
114 gCpuCaps.hasSSE, gCpuCaps.hasSSE2); | |
115 #ifdef RUNTIME_CPUDETECT | |
116 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithRuntimeDetection); | |
117 #else | |
118 mp_msg(MSGT_CPLAYER,MSGL_INFO, MSGTR_CompiledWithCPUExtensions); | |
119 #ifdef HAVE_MMX | |
120 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX"); | |
121 #endif | |
122 #ifdef HAVE_MMX2 | |
123 mp_msg(MSGT_CPLAYER,MSGL_INFO," MMX2"); | |
124 #endif | |
125 #ifdef HAVE_3DNOW | |
126 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNow"); | |
127 #endif | |
128 #ifdef HAVE_3DNOWEX | |
129 mp_msg(MSGT_CPLAYER,MSGL_INFO," 3DNowEx"); | |
130 #endif | |
131 #ifdef HAVE_SSE | |
132 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE"); | |
133 #endif | |
134 #ifdef HAVE_SSE2 | |
135 mp_msg(MSGT_CPLAYER,MSGL_INFO," SSE2"); | |
136 #endif | |
137 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n\n"); | |
138 #endif | |
139 #endif | |
140 console_state = 1; | |
141 } | |
142 } | |
143 | |
144 void capitalize(char *filename) | |
145 { | |
146 unsigned int i; | |
147 BOOL cap = TRUE; | |
148 for (i=0; i < strlen(filename); i++) | |
149 { | |
150 if (cap) | |
151 { | |
152 cap = FALSE; | |
153 filename[i] = toupper(filename[i]); | |
154 } | |
155 else if (filename[i] == ' ') | |
156 cap = TRUE; | |
157 else | |
158 filename[i] = tolower(filename[i]); | |
159 } | |
160 } | |
161 | |
162 static image *get_drawground(HWND hwnd) | |
163 { | |
164 gui_t * gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA); | |
165 unsigned int i; | |
166 if(!gui) return NULL; | |
167 for(i=0; i<gui->window_priv_count; i++) | |
168 if(gui->window_priv[i]->hwnd==hwnd) | |
169 return &gui->window_priv[i]->img; | |
170 return NULL; | |
171 } | |
172 | |
173 static HBITMAP get_bitmap(HWND hwnd) | |
174 { | |
175 gui_t *gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA); | |
176 unsigned int i; | |
177 if(!gui) return NULL; | |
178 for(i=0; i<gui->window_priv_count; i++) | |
179 if(gui->window_priv[i]->hwnd == hwnd) | |
180 return gui->window_priv[i]->bitmap; | |
181 return NULL; | |
182 } | |
183 | |
184 static int get_windowtype(HWND hwnd) | |
185 { | |
186 gui_t *gui = (gui_t *) GetWindowLongPtr(hwnd, GWLP_USERDATA); | |
187 unsigned int i; | |
188 if(!gui) return -1; | |
189 for(i=0; i<gui->window_priv_count; i++) | |
190 if(gui->window_priv[i]->hwnd == hwnd) | |
191 return gui->window_priv[i]->type; | |
192 return -1; | |
193 } | |
194 | |
195 static void uninit(gui_t *gui) | |
196 { | |
197 if(gui->skin) destroy_window(gui); | |
198 if(gui->playlist) gui->playlist->free_playlist(gui->playlist); | |
199 gui->playlist = NULL; | |
200 } | |
201 | |
202 /* | |
203 the gui message handler | |
204 tries to handle the incoming messages | |
205 and passes them to the player's message handler if it can't handle them | |
206 */ | |
207 static void handlemsg(HWND hWnd, int msg) | |
208 { | |
209 gui_t *gui = (gui_t *) GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
210 if(msg == evNone) return; | |
211 | |
212 switch(msg) | |
213 { | |
214 case evLoadPlay: | |
215 case evLoad: | |
216 if(display_openfilewindow(gui, 0) && (msg == evLoadPlay)) | |
217 handlemsg(hWnd, evDropFile); | |
218 return; | |
219 #ifdef USE_SUB | |
220 case evLoadSubtitle: | |
221 display_opensubtitlewindow(gui); | |
222 break; | |
223 #endif | |
224 case evPreferences: | |
225 display_prefswindow(gui); | |
226 return; | |
227 case evPlayList: | |
228 display_playlistwindow(gui); | |
229 return; | |
230 case evSkinBrowser: | |
231 display_skinbrowser(gui); | |
232 break; | |
233 case evEqualizer: | |
234 display_eqwindow(gui); | |
235 break; | |
236 case evAbout: | |
237 MessageBox(hWnd, COPYRIGHT, "About", MB_OK); | |
238 break; | |
239 case evIconify: | |
240 ShowWindow(hWnd, SW_MINIMIZE); | |
241 break; | |
242 case evIncVolume: | |
243 mplayer_put_key(KEY_VOLUME_UP); | |
244 break; | |
245 case evDecVolume: | |
246 mplayer_put_key(KEY_VOLUME_DOWN); | |
247 break; | |
248 default: | |
249 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] received msg %s (%i)\n", gui->skin->geteventname(msg), msg); | |
250 break; | |
251 } | |
252 gui->playercontrol(msg); | |
253 } | |
254 | |
255 static widget *clickedinsidewidget(gui_t *gui, int window, int x, int y) | |
256 { | |
257 unsigned int i; | |
258 widget *item; | |
259 for(i=0; i<gui->skin->widgetcount; i++) | |
260 { | |
261 item = gui->skin->widgets[i]; | |
262 if((item->window == window) && (item->x <= x) && (item->x + item->width >= x) && | |
263 (item->y <= y) && (item->y + item->height >= y)) | |
264 return item; | |
265 } | |
266 return NULL; | |
267 } | |
268 | |
269 /* updates sliders and the display */ | |
270 static void updatedisplay(gui_t *gui, HWND hwnd) | |
271 { | |
272 if(!hwnd) return; | |
273 | |
274 unsigned int i; | |
275 window_priv_t *priv = NULL; | |
276 | |
277 /* load all potmeters hpotmeters */ | |
278 for(i=0; i<gui->skin->widgetcount; i++) | |
279 { | |
280 if(gui->skin->widgets[i]->type == tyHpotmeter || gui->skin->widgets[i]->type == tyPotmeter) | |
281 { | |
282 if(gui->skin->widgets[i]->msg == evSetVolume) | |
283 gui->skin->widgets[i]->value = guiIntfStruct.Volume; | |
284 else if(gui->skin->widgets[i]->msg == evSetMoviePosition) | |
285 gui->skin->widgets[i]->value = guiIntfStruct.Position; | |
286 else if(gui->skin->widgets[i]->msg == evSetBalance) | |
287 gui->skin->widgets[i]->value = guiIntfStruct.Balance; | |
288 if(gui->skin->widgets[i]->window == get_windowtype(hwnd)) | |
289 renderwidget(gui->skin, get_drawground(hwnd), gui->skin->widgets[i], | |
290 gui->skin->widgets[i]->pressed ? 0 : 1); | |
291 } | |
292 /* update some buttons */ | |
293 if(gui->skin->widgets[i]->type == tyButton && gui->skin->widgets[i]->window == get_windowtype(hwnd)) | |
294 { | |
295 if(gui->skin->widgets[i]->msg == evPlaySwitchToPause) | |
296 { | |
297 gui->skin->widgets[i]->value = guiIntfStruct.Playing; | |
298 renderwidget(gui->skin, get_drawground(hwnd), gui->skin->widgets[i], | |
299 guiIntfStruct.Playing == 1 ? 0 : 1); | |
300 } | |
301 if(gui->skin->widgets[i]->msg == evMute) | |
302 { | |
303 gui->skin->widgets[i]->value = guiIntfStruct.Volume; | |
304 renderwidget(gui->skin, get_drawground(hwnd), gui->skin->widgets[i], | |
305 guiIntfStruct.Volume == 0.0f ? 0 : 1); | |
306 } | |
307 } | |
308 } | |
309 | |
310 /* updating the display once a 100.second is enough imo */ | |
311 DWORD time = timeGetTime(); | |
312 if((time - oldtime) < 100) return; | |
313 oldtime=time; | |
314 | |
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
|
315 /* suppress directx's fullscreen window when using the sub window */ |
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
|
316 if(sub_window && &video_driver_list[0] && strstr("directx", video_driver_list[0])) |
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
|
317 { |
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
|
318 HWND hWndFS = NULL; //handle to directx's fullscreen window |
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
|
319 if(hWndFS == NULL) |
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
|
320 { |
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
|
321 hWndFS = FindWindow(NULL, "MPlayer 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
|
322 if(hWndFS != NULL) DestroyWindow(hWndFS); //sub window handles 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
|
323 } |
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
|
324 } |
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
|
325 |
18914 | 326 for (i=0; i<gui->window_priv_count; i++) |
327 { | |
328 if(gui->window_priv[i]->hwnd == hwnd) | |
329 priv=gui->window_priv[i]; | |
330 }// Sherpya | |
331 /* display the status msgs */ | |
332 renderinfobox(gui->skin, priv); | |
333 RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE); | |
334 } | |
335 | |
336 static LRESULT CALLBACK SubProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | |
337 { | |
338 gui_t *gui = (gui_t *) GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
339 if (gui && (gui->subwindow != hWnd)) return FALSE; | |
340 | |
341 switch (message) | |
342 { | |
343 case WM_CLOSE: | |
344 handlemsg(hWnd, evExit); | |
345 return 0; | |
346 case WM_DESTROY: | |
347 PostQuitMessage(0); | |
348 return 0; | |
349 case WM_KEYDOWN: | |
350 { | |
351 switch(wParam) | |
352 { | |
353 case VK_LEFT: | |
354 mplayer_put_key(KEY_LEFT); | |
355 break; | |
356 case VK_UP: | |
357 mplayer_put_key(KEY_UP); | |
358 break; | |
359 case VK_RIGHT: | |
360 mplayer_put_key(KEY_RIGHT); | |
361 break; | |
362 case VK_DOWN: | |
363 mplayer_put_key(KEY_DOWN); | |
364 break; | |
365 case VK_TAB: | |
366 mplayer_put_key(KEY_TAB); | |
367 break; | |
368 case VK_BACK: | |
369 mplayer_put_key(KEY_BS); | |
370 break; | |
371 case VK_DELETE: | |
372 mplayer_put_key(KEY_DELETE); | |
373 break; | |
374 case VK_INSERT: | |
375 mplayer_put_key(KEY_INSERT); | |
376 break; | |
377 case VK_HOME: | |
378 mplayer_put_key(KEY_HOME); | |
379 break; | |
380 case VK_END: | |
381 mplayer_put_key(KEY_END); | |
382 break; | |
383 case VK_PRIOR: | |
384 mplayer_put_key(KEY_PAGE_UP); | |
385 break; | |
386 case VK_NEXT: | |
387 mplayer_put_key(KEY_PAGE_DOWN); | |
388 break; | |
389 case VK_ESCAPE: | |
390 mplayer_put_key(KEY_ESC); | |
391 break; | |
392 } | |
393 break; | |
394 } | |
395 case WM_COMMAND: | |
396 { | |
397 switch(LOWORD(wParam)) | |
398 { | |
399 case IDEXIT: | |
400 PostQuitMessage(0); | |
401 handlemsg(hWnd, evExit); | |
402 break; | |
403 case IDFILE_OPEN: | |
404 handlemsg(hWnd, evLoadPlay); | |
405 break; | |
406 case IDURL_OPEN: | |
407 display_openurlwindow(gui, 0); | |
408 break; | |
409 case IDDIR_OPEN: | |
410 { | |
411 static char path[MAX_PATH]; | |
412 BROWSEINFO bi; | |
413 memset(&bi, 0, sizeof(BROWSEINFO)); | |
414 bi.lpszTitle = "Choose a Directory..."; | |
415 LPITEMIDLIST pidl = SHBrowseForFolder(&bi); | |
416 if (SHGetPathFromIDList(pidl, path)) | |
417 { | |
418 gui->playlist->clear_playlist(gui->playlist); | |
419 adddirtoplaylist(gui->playlist, path, TRUE); | |
420 gui->startplay(gui); | |
421 } | |
422 break; | |
423 } | |
424 case ID_PTRACK: | |
425 handlemsg(hWnd, evPrev); | |
426 break; | |
427 case ID_SEEKB: | |
428 handlemsg(hWnd, evBackward10sec); | |
429 break; | |
430 case ID_PLAY: | |
431 handlemsg(hWnd, evPlaySwitchToPause); | |
432 break; | |
433 case ID_STOP: | |
434 handlemsg(hWnd, evStop); | |
435 break; | |
436 case ID_SEEKF: | |
437 handlemsg(hWnd, evForward10sec); | |
438 break; | |
439 case ID_NTRACK: | |
440 handlemsg(hWnd, evNext); | |
441 break; | |
442 #ifdef USE_DVDREAD | |
443 case ID_CHAPTERSEL: | |
444 display_chapterselwindow(gui); | |
445 break; | |
446 #endif | |
447 case ID_ASPECT1: | |
448 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 1.777777")); | |
449 break; | |
450 case ID_ASPECT2: | |
451 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 1.333333")); | |
452 break; | |
453 case ID_ASPECT3: | |
454 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 2.35")); | |
455 break; | |
456 case ID_ASPECT4: | |
457 mp_input_queue_cmd(mp_input_parse_cmd("switch_ratio 0")); | |
458 break; | |
459 case IDSUB_TOGGLE: | |
460 mp_input_queue_cmd(mp_input_parse_cmd("sub_visibility")); | |
461 break; | |
462 case IDSUB_CYCLE: | |
463 mp_input_queue_cmd(mp_input_parse_cmd("sub_select")); | |
464 break; | |
465 } | |
466 return 0; | |
467 } | |
468 case WM_CHAR: | |
469 mplayer_put_key(wParam); | |
470 break; | |
471 case WM_DROPFILES: | |
472 { | |
473 if(!lParam) | |
474 { | |
475 char file[MAX_PATH]; | |
476 int filecount = DragQueryFile((HDROP) wParam, -1, file, MAX_PATH); | |
477 int i; | |
478 for(i=0; i<filecount; i++) | |
479 { | |
480 DragQueryFile((HDROP) wParam, i, file, MAX_PATH); | |
481 if(!parse_filename(file, playtree, mconfig, 1)) | |
482 gui->playlist->add_track(gui->playlist, file, NULL, NULL, 0); | |
483 } | |
484 DragFinish((HDROP) wParam); | |
485 handlemsg(hWnd, evDropFile); | |
486 } | |
487 else | |
488 { | |
489 gui->playlist->clear_playlist(gui->playlist); | |
490 gui->playlist->add_track(gui->playlist, (const char *) wParam, NULL, NULL, 0); | |
491 handlemsg(hWnd, evDropFile); | |
492 } | |
493 SetForegroundWindow(gui->subwindow); | |
494 return 0; | |
495 } | |
496 case WM_LBUTTONDOWN: | |
497 { | |
498 if(!vo_nomouse_input) | |
499 mplayer_put_key(MOUSE_BTN0); | |
500 break; | |
501 } | |
502 case WM_MBUTTONDOWN: | |
503 { | |
504 if(!vo_nomouse_input) | |
505 mplayer_put_key(MOUSE_BTN1); | |
506 break; | |
507 } | |
508 case WM_RBUTTONDOWN: | |
509 { | |
510 POINT point; | |
511 point.x = GET_X_LPARAM(lParam); | |
512 point.y = GET_Y_LPARAM(lParam); | |
513 ClientToScreen(hWnd, &point); | |
514 if(guiIntfStruct.StreamType == STREAMTYPE_DVD) | |
515 EnableMenuItem(gui->dvdmenu, ID_CHAPTERSEL, MF_BYCOMMAND | MF_ENABLED); | |
516 TrackPopupMenu(gui->submenu, 0, point.x, point.y, 0, hWnd, NULL); | |
517 return 0; | |
518 } | |
519 case WM_LBUTTONDBLCLK: | |
520 { | |
521 if(!vo_nomouse_input) | |
522 mplayer_put_key(MOUSE_BTN0_DBL); | |
523 break; | |
524 } | |
525 case WM_MBUTTONDBLCLK: | |
526 { | |
527 if(!vo_nomouse_input) | |
528 mplayer_put_key(MOUSE_BTN1_DBL); | |
529 break; | |
530 } | |
531 case WM_RBUTTONDBLCLK: | |
532 { | |
533 if(!vo_nomouse_input) | |
534 mplayer_put_key(MOUSE_BTN2_DBL); | |
535 break; | |
536 } | |
537 case WM_MOUSEWHEEL: | |
538 { | |
539 if(vo_nomouse_input) | |
540 break; | |
541 int x = GET_WHEEL_DELTA_WPARAM(wParam); | |
542 if (x > 0) | |
543 mplayer_put_key(MOUSE_BTN3); | |
544 else | |
545 mplayer_put_key(MOUSE_BTN4); | |
546 break; | |
547 } | |
548 case WM_XBUTTONDOWN: | |
549 { | |
550 if(vo_nomouse_input) | |
551 break; | |
552 if(HIWORD(wParam) == 1) | |
553 mplayer_put_key(MOUSE_BTN5); | |
554 else | |
555 mplayer_put_key(MOUSE_BTN6); | |
556 break; | |
557 } | |
558 case WM_XBUTTONDBLCLK: | |
559 { | |
560 if(vo_nomouse_input) | |
561 break; | |
562 if(HIWORD(wParam) == 1) | |
563 mplayer_put_key(MOUSE_BTN5_DBL); | |
564 else | |
565 mplayer_put_key(MOUSE_BTN6_DBL); | |
566 break; | |
567 } | |
568 case WM_WINDOWPOSCHANGED: | |
569 { | |
570 int tmpheight=0; | |
571 static uint32_t rect_width; | |
572 static uint32_t rect_height; | |
573 RECT rd; | |
574 POINT pt; | |
575 while(ShowCursor(TRUE) <= 0){} | |
576 pt.x = 0; | |
577 pt.y = 0; | |
578 GetClientRect(hWnd, &rd); | |
579 ClientToScreen(hWnd, &pt); | |
580 | |
581 rect_width = rd.right - rd.left; | |
582 rect_height = rd.bottom - rd.top; | |
583 | |
584 /* maintain our aspect ratio */ | |
585 tmpheight = ((float)rect_width/sub_aspect); | |
586 tmpheight += tmpheight % 2; | |
587 if(tmpheight > rect_height) | |
588 { | |
589 rect_width = ((float)rect_height*sub_aspect); | |
590 rect_width += rect_width % 2; | |
591 } | |
592 else rect_height = tmpheight; | |
593 | |
594 rd.right = rd.left + rect_width; | |
595 rd.bottom = rd.top + rect_height; | |
596 | |
19408 | 597 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0); |
19245 | 598 SetWindowPos(hWnd, 0, fullscreen?0:pt.x+rd.left, fullscreen?0:pt.y+rd.top, |
19408 | 599 fullscreen?vo_screenwidth:rd.right-rd.left, fullscreen?vo_screenheight:rd.bottom-rd.top, SWP_NOOWNERZORDER); |
600 SetForegroundWindow(hWnd); | |
18914 | 601 return 0; |
602 } | |
603 case WM_PAINT: | |
604 { | |
605 PAINTSTRUCT ps; | |
606 RECT rect; | |
607 HDC hdc = BeginPaint(hWnd, &ps); | |
608 HDC hMemDC = CreateCompatibleDC(hdc); | |
19570
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
609 HBRUSH blackbrush = (HBRUSH)GetStockObject(BLACK_BRUSH); |
18914 | 610 int width, height; |
611 GetClientRect(hWnd, &rect); | |
612 width = rect.right - rect.left; | |
613 height = rect.bottom - rect.top; | |
614 if(guiIntfStruct.Playing == 0) | |
615 { | |
616 int i; | |
617 window *desc = NULL; | |
618 | |
619 for (i=0; i<gui->skin->windowcount; i++) | |
620 if(gui->skin->windows[i]->type == wiSub) | |
621 desc = gui->skin->windows[i]; | |
622 | |
623 SelectObject(hMemDC, get_bitmap(hWnd)); | |
624 StretchBlt(hdc, 0, 0, width, height, hMemDC, 0, 0, desc->base->bitmap[0]->width, | |
625 desc->base->bitmap[0]->height, SRCCOPY); | |
19570
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
626 } else { |
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
627 FillRect(GetDC(hWnd), &rect, fullscreen?blackbrush:colorbrush); |
18914 | 628 } |
629 DeleteDC(hMemDC); | |
630 EndPaint(hWnd, &ps); | |
631 return 0; | |
632 } | |
633 } | |
634 return DefWindowProc(hWnd, message, wParam, lParam); | |
635 } | |
636 | |
637 /* Window Proc for the gui Window */ | |
638 static LRESULT CALLBACK EventProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | |
639 { | |
640 gui_t *gui = (gui_t *) GetWindowLongPtr(hWnd, GWLP_USERDATA); | |
641 | |
642 /* Avoid processing when then window doesn't match gui mainwindow */ | |
643 if (gui && (gui->mainwindow != hWnd)) return FALSE; | |
644 | |
645 switch (message) | |
646 { | |
647 case WM_CLOSE: | |
648 handlemsg(hWnd, evExit); | |
649 return 0; | |
650 case WM_DESTROY: | |
651 PostQuitMessage(0); | |
652 return 0; | |
653 case WM_SYSTRAY: | |
654 { | |
655 switch(lParam) | |
656 { | |
657 POINT cursor; | |
658 case WM_RBUTTONDOWN: | |
659 { | |
660 GetCursorPos(&cursor); | |
661 SetForegroundWindow(hWnd); | |
662 TrackPopupMenu(gui->traymenu, 0, cursor.x, cursor.y, 0, hWnd, NULL); | |
663 break; | |
664 } | |
665 case WM_MBUTTONDBLCLK: | |
666 case WM_LBUTTONDBLCLK: | |
667 { | |
668 if(IsWindowVisible(hWnd)) ShowWindow(hWnd, SW_HIDE); | |
669 else { ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); } | |
670 break; | |
671 } | |
672 } | |
673 break; | |
674 } | |
675 case WM_KEYDOWN: | |
676 { | |
677 switch(wParam) | |
678 { | |
679 case VK_LEFT: | |
680 mplayer_put_key(KEY_LEFT); | |
681 break; | |
682 case VK_UP: | |
683 mplayer_put_key(KEY_UP); | |
684 break; | |
685 case VK_RIGHT: | |
686 mplayer_put_key(KEY_RIGHT); | |
687 break; | |
688 case VK_DOWN: | |
689 mplayer_put_key(KEY_DOWN); | |
690 break; | |
691 case VK_TAB: | |
692 mplayer_put_key(KEY_TAB); | |
693 break; | |
694 case VK_BACK: | |
695 mplayer_put_key(KEY_BS); | |
696 break; | |
697 case VK_DELETE: | |
698 mplayer_put_key(KEY_DELETE); | |
699 break; | |
700 case VK_INSERT: | |
701 mplayer_put_key(KEY_INSERT); | |
702 break; | |
703 case VK_HOME: | |
704 mplayer_put_key(KEY_HOME); | |
705 break; | |
706 case VK_END: | |
707 mplayer_put_key(KEY_END); | |
708 break; | |
709 case VK_PRIOR: | |
710 mplayer_put_key(KEY_PAGE_UP); | |
711 break; | |
712 case VK_NEXT: | |
713 mplayer_put_key(KEY_PAGE_DOWN); | |
714 break; | |
715 case VK_ESCAPE: | |
716 mplayer_put_key(KEY_ESC); | |
717 break; | |
718 } | |
719 break; | |
720 } | |
721 case WM_CHAR: | |
722 mplayer_put_key(wParam); | |
723 break; | |
724 case WM_SYSCOMMAND: | |
725 { | |
726 switch(wParam) | |
727 { | |
728 case SC_SCREENSAVE: | |
729 case SC_MONITORPOWER: | |
730 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>killing screensaver\n" ); | |
731 return 0; | |
732 } | |
733 break; | |
734 } | |
735 case WM_COPYDATA: | |
736 { | |
737 if(lParam) | |
738 { | |
739 PCOPYDATASTRUCT cdData; | |
740 cdData = (PCOPYDATASTRUCT) lParam; | |
741 if(!parse_filename(cdData->lpData, playtree, mconfig, 1)) | |
742 gui->playlist->add_track(gui->playlist, cdData->lpData, NULL, NULL, 0); | |
743 gui->startplay(gui); | |
744 } | |
745 break; | |
746 } | |
747 case WM_DROPFILES: | |
748 { | |
749 if(!lParam) | |
750 { | |
751 char file[MAX_PATH]; | |
752 int filecount = DragQueryFile((HDROP) wParam, -1, file, MAX_PATH); | |
753 int i; | |
754 for(i=0; i<filecount; i++) | |
755 { | |
756 DragQueryFile((HDROP) wParam, i, file, MAX_PATH); | |
757 if(!parse_filename(file, playtree, mconfig, 1)) | |
758 gui->playlist->add_track(gui->playlist, file, NULL, NULL, 0); | |
759 } | |
760 DragFinish((HDROP) wParam); | |
761 handlemsg(hWnd, evDropFile); | |
762 } | |
763 else | |
764 { | |
765 gui->playlist->clear_playlist(gui->playlist); | |
766 gui->playlist->add_track(gui->playlist, (const char *) wParam, NULL, NULL, 0); | |
767 handlemsg(hWnd, evDropFile); | |
768 } | |
769 SetForegroundWindow(gui->mainwindow); | |
770 return 0; | |
771 } | |
772 case WM_LBUTTONDOWN: | |
773 { | |
774 SetCapture(hWnd); | |
775 gui->mousex = GET_X_LPARAM(lParam); | |
776 gui->mousey = GET_Y_LPARAM(lParam); | |
777 /* inside a widget */ | |
778 gui->activewidget = clickedinsidewidget(gui, get_windowtype(hWnd), gui->mousex, gui->mousey); | |
779 if(gui->activewidget) | |
780 { | |
781 gui->activewidget->pressed = 1; | |
782 gui->mousewx = gui->mousex - gui->activewidget->x; | |
783 gui->mousewy = gui->mousey - gui->activewidget->y; | |
784 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 0); | |
785 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
786 handlemsg(hWnd, gui->activewidget->msg); | |
787 } | |
788 break; | |
789 } | |
790 case WM_CAPTURECHANGED: | |
791 { | |
792 if(gui->activewidget) | |
793 { | |
794 gui->activewidget->pressed = 0; | |
795 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 1); | |
796 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
797 gui->activewidget = NULL; | |
798 } | |
799 break; | |
800 } | |
801 case WM_LBUTTONUP: | |
802 { | |
803 ReleaseCapture(); | |
804 if(gui->activewidget) | |
805 { | |
806 gui->activewidget->pressed = 0; | |
807 renderwidget(gui->skin, get_drawground(hWnd), gui->activewidget, 1); | |
808 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE); | |
809 gui->activewidget = NULL; | |
810 } | |
811 break; | |
812 } | |
813 case WM_RBUTTONDOWN: | |
814 { | |
815 POINT point; | |
816 char device[MAX_PATH]; | |
817 char searchpath[MAX_PATH]; | |
818 char searchpath2[MAX_PATH]; | |
819 #ifdef HAVE_LIBCDIO | |
820 char searchpath3[MAX_PATH]; | |
821 #endif | |
822 int len, pos = 0, cdromdrive = 0; | |
823 point.x = GET_X_LPARAM(lParam); | |
824 point.y = GET_Y_LPARAM(lParam); | |
825 ClientToScreen(hWnd, &point); | |
826 len = GetLogicalDriveStrings(MAX_PATH, device); | |
827 while(pos < len) | |
828 { | |
829 if(GetDriveType(device + pos) == DRIVE_CDROM) | |
830 { | |
831 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] checking %s for CD/VCD/SVCD/DVDs\n", device + pos); | |
832 sprintf(searchpath, "%sVIDEO_TS", device + pos); | |
833 sprintf(searchpath2, "%sMpegav", device + pos); | |
834 #ifdef HAVE_LIBCDIO | |
835 sprintf(searchpath3, "%sTrack01.cda", device + pos); | |
836 #endif | |
837 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) | |
838 EnableMenuItem(gui->diskmenu, IDPLAYDISK + cdromdrive, MF_BYCOMMAND | MF_ENABLED); | |
839 else if(GetFileAttributes(searchpath2) != INVALID_FILE_ATTRIBUTES) | |
840 EnableMenuItem(gui->diskmenu, IDPLAYDISK + cdromdrive, MF_BYCOMMAND | MF_ENABLED); | |
841 #ifdef HAVE_LIBCDIO | |
842 else if(GetFileAttributes(searchpath3) != INVALID_FILE_ATTRIBUTES) | |
843 EnableMenuItem(gui->diskmenu, IDPLAYDISK + cdromdrive, MF_BYCOMMAND | MF_ENABLED); | |
844 #endif | |
845 else EnableMenuItem(gui->diskmenu, IDPLAYDISK + cdromdrive, MF_BYCOMMAND | MF_GRAYED); | |
846 cdromdrive++; | |
847 } | |
848 pos += strlen(device + pos) + 1; | |
849 } | |
850 TrackPopupMenu(gui->menu, 0, point.x, point.y, 0, hWnd, NULL); | |
851 return 0; | |
852 } | |
853 case WM_MOUSEMOVE: | |
854 { | |
855 if(wParam & MK_LBUTTON) | |
856 { | |
857 POINT point; | |
858 RECT rect; | |
859 if(gui->activewidget) | |
860 { | |
861 widget *item = gui->activewidget; | |
862 | |
863 if(item->type == tyHpotmeter) | |
864 { | |
865 item->x = GET_X_LPARAM(lParam) - gui->mousewx; | |
866 item->value = (float)((float)((item->x - item->wx) * 100.0f) / (float)(item->wwidth - item->width)); | |
867 } | |
868 if(item->type == tyPotmeter) | |
869 { | |
870 gui->mousewx = GET_X_LPARAM(lParam) - gui->activewidget->x; | |
871 item->value = (float) (gui->mousewx * 100.0f) / (float) item->wwidth; | |
872 } | |
873 | |
874 if((item->type == tyPotmeter) || (item->type == tyHpotmeter) || (item->type == tyVpotmeter)) | |
875 { | |
876 /* Bound checks */ | |
877 if(item->value > 100.0f) | |
878 item->value = 100.0f; | |
879 else if(item->value < 0.0f) | |
880 item->value = 0.0f; | |
881 | |
882 if(item->msg == evSetVolume) | |
883 guiIntfStruct.Volume = (float) item->value; | |
884 else if(item->msg == evSetMoviePosition) | |
885 guiIntfStruct.Position = (float) item->value; | |
886 else if(item->msg == evSetBalance) | |
887 { | |
888 /* make the range for 50% a bit bigger, because the sliders for balance usually suck */ | |
889 if((item->value - 50.0f < 1.5f) && (item->value - 50.0f > -1.5f)) | |
890 item->value = 50.0f; | |
891 guiIntfStruct.Balance = (float) item->value; | |
892 } | |
893 updatedisplay(gui, hWnd); | |
894 handlemsg(hWnd, item->msg); | |
895 } | |
896 break; | |
897 } | |
898 point.x = GET_X_LPARAM(lParam); | |
899 point.y = GET_Y_LPARAM(lParam); | |
900 ClientToScreen(hWnd, &point); | |
901 GetWindowRect(hWnd, &rect); | |
902 MoveWindow(hWnd, point.x - gui->mousex, point.y - gui->mousey, | |
903 rect.right-rect.left,rect.bottom-rect.top,TRUE); | |
904 break; | |
905 } | |
906 break; | |
907 } | |
908 case WM_COMMAND: | |
909 { | |
910 switch(LOWORD(wParam)) | |
911 { | |
912 case IDEXIT: | |
913 PostQuitMessage(0); | |
914 handlemsg(hWnd, evExit); | |
915 break; | |
916 case IDFILE_OPEN: | |
917 handlemsg(hWnd, evLoadPlay); | |
918 break; | |
919 case IDDIR_OPEN: | |
920 { | |
921 static char path[MAX_PATH]; | |
922 BROWSEINFO bi; | |
923 memset(&bi, 0, sizeof(BROWSEINFO)); | |
924 bi.lpszTitle = "Choose a Directory..."; | |
925 LPITEMIDLIST pidl = SHBrowseForFolder(&bi); | |
926 if (SHGetPathFromIDList(pidl, path)) | |
927 { | |
928 gui->playlist->clear_playlist(gui->playlist); | |
929 adddirtoplaylist(gui->playlist, path, TRUE); | |
930 gui->startplay(gui); | |
931 } | |
932 break; | |
933 } | |
934 case ID_SKINBROWSER: | |
935 handlemsg(hWnd, evSkinBrowser); | |
936 break; | |
937 case IDURL_OPEN: | |
938 display_openurlwindow(gui, 0); | |
939 break; | |
940 #ifdef USE_SUB | |
941 case IDSUBTITLE_OPEN: | |
942 display_opensubtitlewindow(gui); | |
943 break; | |
944 #endif | |
945 case ID_PTRACK: | |
946 handlemsg(hWnd, evPrev); | |
947 break; | |
948 case ID_SEEKB: | |
949 handlemsg(hWnd, evBackward10sec); | |
950 break; | |
951 case ID_PLAY: | |
952 handlemsg(hWnd, evPlaySwitchToPause); | |
953 break; | |
954 case ID_STOP: | |
955 handlemsg(hWnd, evStop); | |
956 break; | |
957 case ID_SEEKF: | |
958 handlemsg(hWnd, evForward10sec); | |
959 break; | |
960 case ID_NTRACK: | |
961 handlemsg(hWnd, evNext); | |
962 break; | |
963 case ID_SHOWHIDE: | |
964 { | |
965 if(IsWindowVisible(hWnd)) ShowWindow(hWnd, SW_HIDE); | |
966 else ShowWindow(hWnd, SW_SHOW); | |
967 break; | |
968 } | |
969 case ID_PLAYLIST: | |
970 handlemsg(hWnd, evPlayList); | |
971 break; | |
972 case ID_PREFS: | |
973 handlemsg(hWnd, evPreferences); | |
974 break; | |
975 case ID_CONSOLE: | |
976 console_toggle(); | |
977 break; | |
978 case ID_ONLINEHELP: | |
979 ShellExecute(NULL, "open", ONLINE_HELP_URL, NULL, NULL, SW_SHOWNORMAL); | |
980 break; | |
981 } | |
982 if((IDPLAYDISK <= LOWORD(wParam)) && (LOWORD(wParam) < (IDPLAYDISK + 100))) | |
983 { | |
984 char device[MAX_PATH]; | |
985 char searchpath[MAX_PATH]; | |
986 char filename[MAX_PATH]; | |
987 int len, pos = 0, cdromdrive = 0; | |
988 len = GetLogicalDriveStrings(MAX_PATH, device); | |
989 while(pos < len) | |
990 { | |
991 if(GetDriveType(device + pos)==DRIVE_CDROM) | |
992 { | |
993 if(LOWORD(wParam) - IDPLAYDISK == cdromdrive) | |
994 { | |
995 #ifdef USE_DVDREAD | |
996 sprintf(searchpath, "%sVIDEO_TS", device + pos); | |
997 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) | |
998 { | |
999 if (dvd_device) free(dvd_device); | |
1000 dvd_device = strdup(device + pos); | |
1001 dvd_title = dvd_chapter = dvd_angle = 1; | |
1002 handlemsg(hWnd, evPlayDVD); | |
1003 } | |
1004 #endif | |
1005 #ifdef HAVE_LIBCDIO | |
1006 sprintf(searchpath, "%sTrack01.cda", device + pos); | |
1007 if(GetFileAttributes(searchpath) != INVALID_FILE_ATTRIBUTES) | |
1008 { | |
1009 if (cdrom_device) free(cdrom_device); | |
1010 cdrom_device = strdup(device + pos); | |
1011 /* mplayer doesn't seem to like the trailing \ after the device name */ | |
1012 cdrom_device[2]=0; | |
1013 handlemsg(hWnd, evPlayCD); | |
1014 } | |
1015 #endif | |
1016 else | |
1017 { | |
1018 HANDLE searchhndl; | |
1019 WIN32_FIND_DATA finddata; | |
1020 sprintf(searchpath, "%smpegav\\*.dat", device + pos); | |
1021 if((searchhndl=FindFirstFile(searchpath, &finddata)) != INVALID_HANDLE_VALUE) | |
1022 { | |
1023 mp_msg(MSGT_GPLAYER,MSGL_V, "Opening VCD/SVCD\n"); | |
1024 gui->playlist->clear_playlist(gui->playlist); | |
1025 do | |
1026 { | |
1027 sprintf(filename, "%smpegav\\%s", device + pos, finddata.cFileName); | |
1028 gui->playlist->add_track(gui->playlist, filename, NULL, NULL, 0); | |
1029 } | |
1030 while(FindNextFile(searchhndl, &finddata)); | |
1031 FindClose(searchhndl); | |
1032 } | |
1033 gui->startplay(gui); | |
1034 } | |
1035 } | |
1036 cdromdrive++; | |
1037 } | |
1038 pos += strlen(device + pos) + 1; | |
1039 } | |
1040 } | |
1041 break; | |
1042 } | |
1043 case WM_PAINT: | |
1044 { | |
1045 PAINTSTRUCT ps; | |
1046 RECT rd; | |
1047 HDC hdc = BeginPaint(hWnd, &ps); | |
1048 HDC hMemDC = CreateCompatibleDC(hdc); | |
1049 int width, height; | |
1050 GetClientRect(hWnd, &rd); | |
1051 width = rd.right - rd.left; | |
1052 height = rd.bottom - rd.top; | |
1053 SelectObject(hMemDC, get_bitmap(hWnd)); | |
1054 BitBlt(hdc, 0, 0, width, height, hMemDC, 0, 0, SRCCOPY); | |
1055 DeleteDC(hMemDC); | |
1056 EndPaint(hWnd, &ps); | |
1057 return 0; | |
1058 } | |
1059 return 0; | |
1060 } | |
1061 return DefWindowProc(hWnd, message, wParam, lParam); | |
1062 } | |
1063 | |
1064 inline void startplay(gui_t *gui) | |
1065 { | |
1066 handlemsg(gui->mainwindow, evDropFile); | |
1067 } | |
1068 | |
1069 /* returns the bits per pixel of the desktop */ | |
1070 /* the format is always in BGR byte order */ | |
1071 static int GetDesktopBitsPerPixel(void) | |
1072 { | |
1073 HWND desktop=GetDesktopWindow(); | |
1074 HDC dc=GetDC(desktop); | |
1075 int bpp=GetDeviceCaps(dc, BITSPIXEL); | |
1076 ReleaseDC(desktop, dc); | |
1077 return bpp; | |
1078 } | |
1079 | |
1080 /* unloads a skin and destroys its windows */ | |
1081 extern int destroy_window(gui_t *gui) | |
1082 { | |
1083 RECT rd; | |
1084 unsigned int i; | |
1085 | |
1086 /* Save position: MSDN says don't pass workspace coordinates | |
1087 * to CreateWindow() or SetWindowPos(), as both of which expect | |
1088 * screen coordinates; resulting in the window appearing in the | |
1089 * wrong location. | |
1090 * -Erik | |
1091 */ | |
1092 | |
1093 /* main window position */ | |
1094 if(IsIconic(gui->mainwindow)) | |
1095 ShowWindow(gui->mainwindow, SW_SHOWNORMAL); | |
1096 GetWindowRect(gui->mainwindow, &rd); | |
1097 gui_main_pos_x = rd.left; | |
1098 gui_main_pos_y = rd.top; | |
1099 | |
1100 /* sub window position */ | |
1101 if(IsIconic(gui->subwindow)) | |
1102 ShowWindow(gui->subwindow, SW_SHOWNORMAL); | |
1103 GetWindowRect(gui->subwindow, &rd); | |
1104 gui_sub_pos_x = rd.left; | |
1105 gui_sub_pos_y = rd.top; | |
1106 | |
1107 for(i=0; i<gui->window_priv_count; i++) | |
1108 { | |
1109 if(gui->window_priv[i]->bitmap) | |
1110 DeleteObject(gui->window_priv[i]->bitmap); | |
1111 free(gui->window_priv[i]); | |
1112 } | |
1113 free(gui->window_priv); | |
1114 gui->window_priv = NULL; | |
1115 gui->window_priv_count = 0; | |
1116 | |
1117 /* destroy the main window */ | |
1118 if(gui->mainwindow) | |
1119 DestroyWindow(gui->mainwindow); | |
1120 gui->mainwindow = NULL; | |
1121 | |
1122 /* destroy the sub window */ | |
1123 if(gui->subwindow) | |
1124 DestroyWindow(gui->subwindow); | |
1125 gui->subwindow = NULL; | |
1126 | |
1127 UnregisterClass(gui->classname, 0); | |
1128 DestroyIcon(gui->icon); | |
1129 | |
1130 gui->skin->freeskin(gui->skin); | |
1131 gui->skin = NULL; | |
1132 return 0; | |
1133 } | |
1134 | |
1135 static void create_menu(gui_t *gui) | |
1136 { | |
1137 char device[MAX_PATH]; | |
1138 char volname[MAX_PATH]; | |
1139 char menuitem[MAX_PATH]; | |
1140 int len, pos = 0, cdromdrive = 0; | |
1141 gui->diskmenu = CreatePopupMenu(); | |
1142 len = GetLogicalDriveStrings(MAX_PATH, device); | |
1143 while(pos < len) | |
1144 { | |
1145 if(GetDriveType(device + pos) == DRIVE_CDROM) | |
1146 { | |
1147 volname[0] = 0; | |
1148 menuitem[0] = 0; | |
1149 strcat(menuitem, device + pos); | |
1150 menuitem[strlen(menuitem) - 1]=0; | |
1151 GetVolumeInformation(device + pos, volname, MAX_PATH, NULL, NULL, NULL, NULL, 0); | |
1152 if (strlen(volname)) | |
1153 { | |
1154 capitalize(volname); | |
1155 strcat(menuitem, " - "); | |
1156 strcat(menuitem, volname); | |
1157 } | |
1158 AppendMenu(gui->diskmenu, MF_STRING, IDPLAYDISK + cdromdrive, menuitem); | |
1159 cdromdrive++; | |
1160 } | |
1161 pos += strlen(device + pos) + 1; | |
1162 } | |
1163 gui->menu=CreatePopupMenu(); | |
1164 gui->trayplaymenu = CreatePopupMenu(); | |
1165 AppendMenu(gui->menu, MF_STRING | MF_POPUP, (UINT) gui->trayplaymenu, "Open..."); | |
1166 AppendMenu(gui->trayplaymenu, MF_STRING, IDFILE_OPEN, "File..."); | |
1167 AppendMenu(gui->trayplaymenu, MF_STRING, IDURL_OPEN, "Url..."); | |
1168 AppendMenu(gui->trayplaymenu, MF_STRING, IDDIR_OPEN, "Directory..."); | |
1169 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); | |
1170 AppendMenu(gui->menu, MF_STRING | MF_POPUP, (UINT) gui->diskmenu, "Play &CD/DVD/VCD/SVCD"); | |
1171 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); | |
1172 #ifdef USE_SUB | |
1173 AppendMenu(gui->menu, MF_STRING, IDSUBTITLE_OPEN, "Open Subtitle"); | |
1174 #endif | |
1175 AppendMenu(gui->menu, MF_STRING, ID_SKINBROWSER, "Skin Browser"); | |
1176 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); | |
1177 AppendMenu(gui->menu, MF_STRING, ID_PREFS, "Preferences"); | |
1178 AppendMenu(gui->menu, MF_STRING, ID_CONSOLE, "Debug Console"); | |
1179 AppendMenu(gui->menu, MF_STRING, ID_ONLINEHELP, "Online Help"); | |
1180 AppendMenu(gui->menu, MF_SEPARATOR, 0, 0); | |
1181 AppendMenu(gui->menu, MF_STRING, IDEXIT, "&Exit"); | |
1182 } | |
1183 | |
1184 static void create_traymenu(gui_t *gui) | |
1185 { | |
1186 gui->traymenu = CreatePopupMenu(); | |
1187 gui->trayplaybackmenu = CreatePopupMenu(); | |
1188 AppendMenu(gui->traymenu, MF_STRING | MF_POPUP, (UINT) gui->trayplaymenu, "Open..."); | |
1189 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1190 AppendMenu(gui->traymenu, MF_STRING | MF_POPUP, (UINT) gui->trayplaybackmenu, "Playback"); | |
1191 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_SEEKB, "Seek Backwards"); | |
1192 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_PTRACK, "Previous Track"); | |
1193 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_PLAY, "Play/Pause"); | |
1194 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_STOP, "Stop"); | |
1195 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_NTRACK, "Next Track"); | |
1196 AppendMenu(gui->trayplaybackmenu, MF_STRING, ID_SEEKF, "Seek Forwards"); | |
1197 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1198 #ifdef USE_SUB | |
1199 AppendMenu(gui->traymenu, MF_STRING, IDSUBTITLE_OPEN, "Open Subtitle"); | |
1200 #endif | |
1201 AppendMenu(gui->traymenu, MF_STRING, ID_PLAYLIST, "Playlist"); | |
1202 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1203 AppendMenu(gui->traymenu, MF_STRING, ID_SHOWHIDE, "Show/Hide"); | |
1204 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1205 AppendMenu(gui->traymenu, MF_STRING, ID_PREFS, "Preferences"); | |
1206 AppendMenu(gui->traymenu, MF_STRING, ID_CONSOLE, "Debug Console"); | |
1207 AppendMenu(gui->traymenu, MF_STRING, ID_ONLINEHELP, "Online Help"); | |
1208 AppendMenu(gui->traymenu, MF_SEPARATOR, 0, 0); | |
1209 AppendMenu(gui->traymenu, MF_STRING, IDEXIT, "&Exit"); | |
1210 } | |
1211 | |
1212 static void create_submenu(gui_t *gui) | |
1213 { | |
1214 gui->submenu = CreatePopupMenu(); | |
1215 gui->dvdmenu = CreatePopupMenu(); | |
1216 gui->aspectmenu = CreatePopupMenu(); | |
1217 gui->subtitlemenu = CreatePopupMenu(); | |
1218 AppendMenu(gui->submenu, MF_STRING | MF_POPUP, (UINT) gui->trayplaymenu, "Open..."); | |
1219 AppendMenu(gui->submenu, MF_SEPARATOR, 0, 0); | |
1220 AppendMenu(gui->submenu, MF_STRING, ID_SEEKB, "Seek Backwards"); | |
1221 AppendMenu(gui->submenu, MF_STRING, ID_PTRACK, "Previous Track"); | |
1222 AppendMenu(gui->submenu, MF_STRING, ID_PLAY, "Play/Pause"); | |
1223 AppendMenu(gui->submenu, MF_STRING, ID_STOP, "Stop"); | |
1224 AppendMenu(gui->submenu, MF_STRING, ID_NTRACK, "Next Track"); | |
1225 AppendMenu(gui->submenu, MF_STRING, ID_SEEKF, "Seek Forwards"); | |
1226 AppendMenu(gui->submenu, MF_SEPARATOR, 0, 0); | |
1227 AppendMenu(gui->submenu, MF_STRING | MF_POPUP, (UINT) gui->aspectmenu, "Aspect Ratio"); | |
1228 AppendMenu(gui->submenu, MF_STRING | MF_POPUP, (UINT) gui->subtitlemenu, "Subtitle Options"); | |
1229 AppendMenu(gui->submenu, MF_STRING | MF_POPUP, (UINT) gui->dvdmenu, "DVD Options"); | |
1230 #ifdef USE_DVDREAD | |
1231 AppendMenu(gui->dvdmenu, MF_STRING | MF_GRAYED, ID_CHAPTERSEL, "Select Title/Chapter..."); | |
1232 #endif | |
1233 AppendMenu(gui->subtitlemenu, MF_STRING, IDSUB_TOGGLE, "Subtitle Visibility On/Off"); | |
1234 AppendMenu(gui->subtitlemenu, MF_STRING, IDSUB_CYCLE, "Cycle Subtitle Languages"); | |
1235 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT1, "Set 16:9"); | |
1236 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT2, "Set 4:3"); | |
1237 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT3, "Set 2.35"); | |
1238 AppendMenu(gui->aspectmenu, MF_SEPARATOR, 0, 0); | |
1239 AppendMenu(gui->aspectmenu, MF_STRING, ID_ASPECT4, "Original Aspect"); | |
1240 AppendMenu(gui->submenu, MF_SEPARATOR, 0, 0); | |
1241 AppendMenu(gui->submenu, MF_STRING, IDEXIT, "&Exit"); | |
1242 } | |
1243 | |
1244 static void maketransparent(HWND hwnd, COLORREF crTransparent) | |
1245 { | |
1246 HDC mdc = GetDC(hwnd); | |
1247 RECT rd; | |
1248 HRGN crRgnres, crRgn, crRgnTmp; | |
1249 int iX = 0, iY = 0, iLeftX = 0; | |
1250 int width, height; | |
1251 GetWindowRect(hwnd, &rd); | |
1252 width = rd.right - rd.left; | |
1253 height = rd.bottom - rd.top; | |
1254 | |
1255 /* create an empty region */ | |
1256 crRgn = CreateRectRgn(0, 0, 0, 0); | |
1257 | |
1258 /* Create a region from a bitmap with transparency colour of Purple */ | |
1259 for (iY = -1; iY < height; iY++) | |
1260 { | |
1261 do | |
1262 { | |
1263 /* skip over transparent pixels at start of lines */ | |
1264 while (iX <= width && GetPixel(mdc,iX, iY) == crTransparent) iX++; | |
1265 | |
1266 /* remember this pixel */ | |
1267 iLeftX = iX; | |
1268 | |
1269 /* now find first non transparent pixel */ | |
1270 while (iX <= width && GetPixel(mdc,iX, iY) != crTransparent) ++iX; | |
1271 | |
1272 /* create a temp region on this info */ | |
1273 crRgnTmp = CreateRectRgn(iLeftX, iY, iX, iY+1); | |
1274 | |
1275 /* combine into main region */ | |
1276 crRgnres = crRgn; | |
1277 CombineRgn(crRgnres, crRgn, crRgnTmp, RGN_OR); | |
1278 crRgn = crRgnres; | |
1279 | |
1280 /* delete the temp region for next pass (otherwise you'll get an ASSERT) */ | |
1281 DeleteObject(crRgnTmp); | |
1282 } while (iX < width); | |
1283 iX = 0; | |
1284 } | |
1285 SetWindowRgn(hwnd, crRgn, TRUE); | |
1286 DeleteObject(crRgn); | |
1287 ReleaseDC(hwnd,mdc); | |
1288 } | |
1289 | |
1290 static int window_render(gui_t *gui, HWND hWnd, HDC hdc, window_priv_t *priv, window *desc, BITMAPINFO binfo) | |
1291 { | |
1292 int i; | |
1293 SetWindowLongPtr(hWnd, GWLP_USERDATA, (DWORD) gui); | |
1294 (gui->window_priv_count)++; | |
1295 gui->window_priv = realloc(gui->window_priv, sizeof(window_priv_t *) * gui->window_priv_count); | |
1296 priv = gui->window_priv[gui->window_priv_count - 1] = calloc(1, sizeof(window_priv_t)); | |
1297 priv->hwnd = hWnd; | |
1298 priv->type = desc->type; | |
1299 priv->background = desc->base->bitmap[0]; | |
1300 memcpy(&priv->img, desc->base->bitmap[0], sizeof(image)); | |
1301 hdc = GetDC(hWnd); | |
1302 binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
1303 binfo.bmiHeader.biWidth = priv->img.width; | |
1304 binfo.bmiHeader.biHeight = -priv->img.height; | |
1305 binfo.bmiHeader.biPlanes = 1; | |
1306 binfo.bmiHeader.biSizeImage = priv->img.width * priv->img.height * (gui->screenbpp / 8); | |
1307 binfo.bmiHeader.biXPelsPerMeter = 0; | |
1308 binfo.bmiHeader.biYPelsPerMeter = 0; | |
1309 binfo.bmiHeader.biClrUsed = 0; | |
1310 binfo.bmiHeader.biClrImportant = 0; | |
1311 binfo.bmiHeader.biBitCount = gui->screenbpp; | |
1312 binfo.bmiHeader.biCompression = BI_RGB; | |
1313 priv->bitmap = CreateDIBSection(hdc, &binfo, DIB_RGB_COLORS, (void **) &priv->img.data, NULL, 0); | |
1314 if(!priv->bitmap) | |
1315 { | |
1316 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] unable to create bitmap for skinned window\n"); | |
1317 return 0; | |
1318 } | |
1319 memcpy(priv->img.data, desc->base->bitmap[0]->data, binfo.bmiHeader.biSizeImage); | |
1320 ReleaseDC(hWnd,hdc); | |
1321 | |
1322 for (i=0; i<gui->skin->widgetcount; i++) | |
1323 if(gui->skin->widgets[i]->window == desc->type) | |
1324 renderwidget(gui->skin, &priv->img, gui->skin->widgets[i], 1); | |
1325 | |
1326 return 0; | |
1327 } | |
1328 | |
1329 /* creates the sub (AKA video) window,*/ | |
1330 extern int create_subwindow(gui_t *gui, char *skindir) | |
1331 { | |
1332 HINSTANCE instance = GetModuleHandle(NULL); | |
1333 WNDCLASS wc; | |
1334 RECT rect; | |
1335 HWND hWnd; | |
1336 DWORD style = 0; | |
1337 HDC hdc = NULL; | |
1338 BITMAPINFO binfo; | |
1339 window_priv_t *priv = NULL; | |
1340 window *desc = NULL; | |
1341 int i, x = -1, y = -1; | |
19570
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
1342 vo_colorkey = 0xff00ff; |
18914 | 1343 |
1344 for (i=0; i<gui->skin->windowcount; i++) | |
1345 if(gui->skin->windows[i]->type == wiSub) | |
1346 desc = gui->skin->windows[i]; | |
1347 | |
1348 if(!desc) | |
1349 { | |
1350 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] Invalid skin description\n"); | |
1351 return 1; | |
1352 } | |
1353 | |
19570
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
1354 windowcolor = vo_colorkey; |
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
1355 colorbrush = CreateSolidBrush(windowcolor); |
18914 | 1356 wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; |
1357 wc.lpfnWndProc = SubProc; | |
1358 wc.cbClsExtra = 0; | |
1359 wc.cbWndExtra = 0; | |
1360 wc.hInstance = instance; | |
1361 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
1362 wc.hIcon = gui->icon; | |
19570
e9ea7852e803
vo_colorkey change to avoid clashes with other black windows
vayne
parents:
19535
diff
changeset
|
1363 wc.hbrBackground = NULL; //WM_PAINT will handle background color switching; |
18914 | 1364 wc.lpszClassName = "MPlayer Sub for Windows"; |
1365 wc.lpszMenuName = NULL; | |
1366 RegisterClass(&wc); | |
1367 | |
1368 /* create the sub window menu */ | |
1369 create_submenu(gui); | |
1370 | |
1371 rect.top = rect.left = 100; | |
1372 rect.bottom = rect.top+desc->base->bitmap[0]->height; | |
1373 rect.right = rect.left+desc->base->bitmap[0]->width; | |
1374 | |
1375 /* our window aspect */ | |
1376 sub_aspect = (float)(rect.right-rect.left)/(rect.bottom-rect.top); | |
1377 | |
19571
a894b3a3d28c
bug fix for starting gmplayer with -fs when using the sub window
vayne
parents:
19570
diff
changeset
|
1378 style = fullscreen?WS_VISIBLE | WS_POPUP:WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_MINIMIZEBOX; |
18914 | 1379 AdjustWindowRect(&rect, style, 0); |
1380 | |
1381 if (gui_sub_pos_x >= 0) | |
1382 x = gui_sub_pos_x; | |
1383 if (gui_sub_pos_y >= 0) | |
1384 y = gui_sub_pos_y; | |
1385 | |
1386 /* out of bounds check */ | |
1387 if (x <= -1 || (x+(rect.right-rect.left) > GetSystemMetrics(SM_CXSCREEN))) | |
1388 x = CW_USEDEFAULT; | |
1389 if (y <= -1 || (y+(rect.bottom-rect.top) > GetSystemMetrics(SM_CYSCREEN))) | |
1390 y = x; | |
1391 | |
1392 hWnd = CreateWindowEx(0, "MPlayer Sub for Windows", "MPlayer for Windows", style, | |
1393 x, y, rect.right-rect.left, rect.bottom-rect.top, | |
1394 gui->subwindow, NULL, instance, NULL); | |
1395 | |
1396 /* load all the window images */ | |
1397 window_render(gui, hWnd, hdc, priv, desc, binfo); | |
1398 | |
1399 /* enable drag and drop support */ | |
1400 DragAcceptFiles(hWnd, TRUE); | |
1401 | |
1402 gui->subwindow = hWnd; | |
1403 if(sub_window) | |
1404 WinID = gui->subwindow; | |
1405 ShowWindow(gui->subwindow, SW_SHOW); | |
1406 UpdateWindow(gui->subwindow); | |
1407 return 0; | |
1408 } | |
1409 | |
1410 /* loads/updates a skin and creates windows for it */ | |
1411 extern int create_window(gui_t *gui, char *skindir) | |
1412 { | |
1413 HINSTANCE instance = GetModuleHandle(NULL); | |
1414 WNDCLASS wc; | |
1415 RECT rect; | |
1416 DWORD style = 0; | |
1417 HWND hwnd; | |
1418 HDC hdc = NULL; | |
1419 BITMAPINFO binfo; | |
1420 window_priv_t *priv = NULL; | |
1421 window *desc = NULL; | |
1422 char dir[MAX_PATH]; | |
1423 unsigned int i; | |
1424 | |
1425 /* destroy the current main window */ | |
1426 if(gui->skin) destroy_window(gui); | |
1427 | |
1428 /* get screenproperties */ | |
1429 gui->screenbpp = GetDesktopBitsPerPixel(); | |
1430 gui->screenw = GetSystemMetrics(SM_CXSCREEN); | |
1431 gui->screenh = GetSystemMetrics(SM_CYSCREEN); | |
1432 | |
1433 /* load the new skin */ | |
1434 gui->skin = loadskin(skindir, gui->screenbpp); | |
1435 if(!gui->skin) | |
1436 { | |
1437 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] fatal error during skinload\n"); | |
1438 /* Set default Skin */ | |
1439 if (skinName) free(skinName); | |
1440 skinName = strdup("Blue"); | |
1441 /* then force write conf */ | |
1442 cfg_write(); | |
1443 return 1; | |
1444 } | |
1445 | |
1446 /* find the description of the mainwindow */ | |
1447 for (i=0; i<gui->skin->windowcount; i++) | |
1448 if(gui->skin->windows[i]->type == wiMain) | |
1449 desc = gui->skin->windows[i]; | |
1450 | |
1451 if(!desc) | |
1452 { | |
1453 mp_msg(MSGT_GPLAYER, MSGL_FATAL, "[GUI] Invalid skin description\n"); | |
1454 return 1; | |
1455 } | |
1456 | |
1457 /* load the icon from the executable */ | |
1458 GetModuleFileName(NULL, dir, MAX_PATH); | |
1459 gui->icon = ExtractIcon(instance, dir, 0); | |
1460 int x = -1, y = -1; | |
1461 | |
1462 /* create the window class */ | |
1463 wc.style = CS_HREDRAW | CS_VREDRAW; | |
1464 wc.lpfnWndProc = EventProc; | |
1465 wc.cbClsExtra = 0; | |
1466 wc.cbWndExtra = 0; | |
1467 wc.hInstance = instance; | |
1468 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
1469 wc.hIcon = gui->icon; | |
1470 wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); | |
1471 wc.lpszClassName = gui->classname = "MPlayer GUI for Windows"; | |
1472 wc.lpszMenuName = NULL; | |
1473 RegisterClass(&wc); | |
1474 | |
1475 /* create a context menu */ | |
1476 create_menu(gui); | |
1477 /* create the systray menu */ | |
1478 create_traymenu(gui); | |
1479 | |
1480 /* create the mainwindow */ | |
1481 /* TODO implement aligning as described in skin.html */ | |
1482 rect.top = rect.left = 100; | |
1483 rect.bottom = rect.top+desc->base->bitmap[0]->height; | |
1484 rect.right = rect.left+desc->base->bitmap[0]->width; | |
1485 if(desc->decoration) style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; | |
1486 else style = WS_POPUP | WS_SYSMENU; | |
1487 | |
1488 AdjustWindowRect(&rect, style, 0); | |
1489 | |
1490 /* Check if out of screen */ | |
1491 if (gui_main_pos_x >= 0) | |
1492 x = gui_main_pos_x; | |
1493 if (gui_main_pos_y >= 0) | |
1494 y = gui_main_pos_y; | |
1495 | |
1496 if (x <= -1 || (x+(rect.right-rect.left) > GetSystemMetrics(SM_CXFULLSCREEN))) | |
1497 { | |
1498 x = (GetSystemMetrics(SM_CXSCREEN) / 2) - ((rect.right-rect.left) / 2); | |
1499 gui_main_pos_x = x; | |
1500 } | |
1501 if (y <= -1 || (y+(rect.bottom-rect.top) > GetSystemMetrics(SM_CYFULLSCREEN))) | |
1502 { | |
1503 y = ((GetSystemMetrics(SM_CYSCREEN)-40) - (rect.bottom-rect.top)); | |
1504 gui_main_pos_y = y; | |
1505 } | |
1506 | |
1507 hwnd = CreateWindowEx(0, gui->classname, "MPlayer for Windows", style, | |
1508 x, y, rect.right-rect.left, rect.bottom-rect.top, | |
1509 gui->mainwindow, NULL, instance, NULL); | |
1510 | |
1511 /* set the systray icon properties */ | |
1512 nid.cbSize = sizeof(NOTIFYICONDATA); | |
1513 nid.hWnd = hwnd; | |
1514 nid.uID = 1; | |
1515 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; | |
1516 nid.uCallbackMessage = WM_SYSTRAY; | |
1517 nid.hIcon = gui->icon; | |
1518 strcpy(nid.szTip, "MPlayer for Windows"); | |
1519 | |
1520 /* register the systray icon */ | |
1521 Shell_NotifyIcon(NIM_ADD, &nid); | |
1522 | |
1523 /* load all the window images */ | |
1524 window_render(gui, hwnd, hdc, priv, desc, binfo); | |
1525 | |
1526 /* enable drag and drop support */ | |
1527 DragAcceptFiles(hwnd, TRUE); | |
1528 | |
1529 updatedisplay(gui, hwnd); | |
1530 gui->mainwindow = hwnd; | |
1531 | |
1532 /* display */ | |
1533 ShowWindow(gui->mainwindow, SW_SHOW); | |
1534 UpdateWindow(gui->mainwindow); | |
1535 maketransparent(gui->mainwindow, RGB(255, 0, 255)); | |
1536 return 0; | |
1537 } | |
1538 | |
1539 gui_t *create_gui(char *skindir, char *skinName, void (*playercontrol)(int event)) | |
1540 { | |
1541 gui_t *gui = calloc(1, sizeof(gui_t)); | |
1542 | |
1543 HWND runningmplayer = FindWindow("MPlayer GUI for Windows", "MPlayer for Windows"); | |
1544 if(runningmplayer) | |
1545 { | |
1546 free(gui); | |
1547 return NULL; | |
1548 } | |
1549 | |
1550 gui->startplay = startplay; | |
1551 gui->playercontrol = playercontrol; | |
1552 gui->uninit = uninit; | |
1553 gui->updatedisplay = updatedisplay; | |
1554 | |
1555 /* create playlist */ | |
1556 gui->playlist = create_playlist(); | |
1557 | |
1558 if(!skinName) skinName = strdup("Blue"); | |
1559 char temp[MAX_PATH]; | |
1560 sprintf(temp, "%s\\%s", skindir, skinName); | |
1561 if(create_window(gui, temp)) return NULL; | |
1562 if(create_subwindow(gui, temp)) return NULL; | |
1563 if(console) console_toggle(); | |
1564 return gui; | |
1565 } |