Mercurial > mplayer.hg
annotate gui/ui/actions.c @ 35452:f42cc2361ee4
Cosmetic: Rename uiSetFileName().
author | ib |
---|---|
date | Sat, 01 Dec 2012 19:05:24 +0000 |
parents | b3efe5e9f0bf |
children | c8f3bba6250a |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
4 * MPlayer is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * MPlayer is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License along | |
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 */ | |
23077 | 18 |
35437 | 19 /** |
20 * @file | |
21 * @brief User interface actions | |
22 */ | |
23 | |
23077 | 24 #include <stdlib.h> |
25 #include <string.h> | |
26 | |
33556 | 27 #include "actions.h" |
32881 | 28 #include "gmplayer.h" |
29 #include "gui/app.h" | |
35429 | 30 #include "gui/gui.h" |
32881 | 31 #include "gui/interface.h" |
32 #include "gui/skin/skin.h" | |
33742
e1539e14d60f
Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents:
33740
diff
changeset
|
33 #include "gui/util/list.h" |
33739 | 34 #include "gui/util/mem.h" |
33737 | 35 #include "gui/util/string.h" |
35435 | 36 #include "gui/wm/ws.h" |
32881 | 37 #include "gui/wm/wsxdnd.h" |
23077 | 38 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
39 #include "help_mp.h" |
32881 | 40 #include "input/input.h" |
35431 | 41 #include "libmpdemux/demuxer.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
42 #include "libvo/video_out.h" |
32881 | 43 #include "mp_core.h" |
35435 | 44 #include "mp_msg.h" |
45 #include "mplayer.h" | |
23077 | 46 |
35437 | 47 /** |
48 * @brief Switch video window fullscreen mode. | |
49 * | |
50 * Switch normal video to fullscreen and fullscreen video to normal. | |
51 */ | |
33555 | 52 void uiFullScreen(void) |
23077 | 53 { |
33960 | 54 if (!guiInfo.VideoWindow) |
32881 | 55 return; |
56 | |
34697 | 57 wsFullScreen(&guiApp.videoWindow); |
23077 | 58 |
34697 | 59 vo_fs = guiApp.videoWindow.isFullScreen; |
23077 | 60 |
34697 | 61 wsSetLayer(wsDisplay, guiApp.mainWindow.WindowID, guiApp.videoWindow.isFullScreen); |
32881 | 62 |
33555 | 63 if (guiApp.menuIsPresent) |
34697 | 64 wsSetLayer(wsDisplay, guiApp.menuWindow.WindowID, guiApp.videoWindow.isFullScreen); |
32881 | 65 |
33555 | 66 if (guiInfo.Playing) |
34697 | 67 wsSetBackgroundRGB(&guiApp.videoWindow, 0, 0, 0); |
32881 | 68 else |
34697 | 69 wsSetBackgroundRGB(&guiApp.videoWindow, guiApp.video.R, guiApp.video.G, guiApp.video.B); |
23077 | 70 } |
71 | |
35437 | 72 /** |
73 * @brief Switch to play mode. | |
74 */ | |
33555 | 75 void uiPlay(void) |
23077 | 76 { |
34401
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
77 if (guiInfo.Playing == GUI_PLAY) |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
78 return; |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
79 |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
80 if (guiInfo.StreamType != STREAMTYPE_CDDA && |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
81 guiInfo.StreamType != STREAMTYPE_VCD && |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
82 guiInfo.StreamType != STREAMTYPE_DVD && |
af8838c2b60b
Allow uiPlay() without guiInfo.Filename for some stream types.
ib
parents:
34400
diff
changeset
|
83 (!guiInfo.Filename || (guiInfo.Filename[0] == 0))) |
32881 | 84 return; |
23077 | 85 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
86 if (guiInfo.Playing == GUI_PAUSE) { |
33555 | 87 uiPause(); |
32881 | 88 return; |
89 } | |
90 | |
33731
81f71d910333
Cosmetic: Change prefix for symbolic constants from GMP to GUI.
ib
parents:
33725
diff
changeset
|
91 gui(GUI_SET_STATE, (void *)GUI_PLAY); |
34697 | 92 uiVideoRender = 0; |
93 wsSetBackgroundRGB(&guiApp.videoWindow, 0, 0, 0); | |
35357
80fe9ad7f318
Pass guiApp's wsTWindow parameters always by reference (if possible).
ib
parents:
34697
diff
changeset
|
94 wsClearWindow(&guiApp.videoWindow); |
23077 | 95 } |
96 | |
35437 | 97 /** |
98 * @brief Switch to pause mode. | |
99 */ | |
33555 | 100 void uiPause(void) |
23077 | 101 { |
33555 | 102 if (!guiInfo.Playing) |
32881 | 103 return; |
104 | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
105 if (guiInfo.Playing == GUI_PLAY) { |
32881 | 106 mp_cmd_t *cmd = calloc(1, sizeof(*cmd)); |
35433 | 107 |
35432 | 108 if (cmd) { |
35433 | 109 cmd->id = MP_CMD_PAUSE; |
110 cmd->name = strdup("pause"); | |
111 mp_input_queue_cmd(cmd); | |
35432 | 112 } |
32881 | 113 } else |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
114 guiInfo.Playing = GUI_PLAY; |
23077 | 115 } |
116 | |
35437 | 117 /** |
118 * @brief Adjust GUI items to reflect current state (i.e. current playing mode). | |
119 */ | |
33555 | 120 void uiState(void) |
32881 | 121 { |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
122 if (guiInfo.Playing == GUI_STOP || guiInfo.Playing == GUI_PAUSE) { |
33978 | 123 btnSet(evPlaySwitchToPause, btnReleased); |
124 btnSet(evPauseSwitchToPlay, btnDisabled); | |
32881 | 125 } else { |
35434 | 126 btnSet(evPauseSwitchToPlay, btnReleased); |
33978 | 127 btnSet(evPlaySwitchToPause, btnDisabled); |
32881 | 128 } |
23077 | 129 } |
130 | |
35437 | 131 /** |
132 * @brief Seek new playback position. | |
133 * | |
35438 | 134 * The new position is a relative one. |
35437 | 135 * |
136 * @param sec seconds to seek (either forward (> 0) or backward (< 0)) | |
137 */ | |
33555 | 138 void uiRelSeek(float sec) |
32881 | 139 { |
32971 | 140 rel_seek_secs = sec; |
32881 | 141 abs_seek_pos = 0; |
142 } | |
143 | |
35437 | 144 /** |
145 * @brief Seek new playback position. | |
146 * | |
35438 | 147 * The new position is an absolute one. |
35437 | 148 * |
149 * @param percent percentage of playback time to position to | |
150 */ | |
33555 | 151 void uiAbsSeek(float percent) |
32881 | 152 { |
32971 | 153 rel_seek_secs = percent / 100.0; |
35431 | 154 abs_seek_pos = SEEK_ABSOLUTE | SEEK_FACTOR; |
23077 | 155 } |
156 | |
35437 | 157 /** |
158 * @brief Change to a different skin. | |
159 * | |
160 * @param name name of the skin to change to | |
161 */ | |
33555 | 162 void uiChangeSkin(char *name) |
23077 | 163 { |
32893 | 164 int prev, bprev; |
32881 | 165 |
33555 | 166 prev = guiApp.menuIsPresent; |
167 bprev = guiApp.playbarIsPresent; | |
32881 | 168 |
169 mainVisible = 0; | |
170 | |
32893 | 171 if (skinRead(name) != 0) { |
172 if (skinRead(skinName) != 0) { | |
32894 | 173 mainVisible = 1; |
174 return; | |
32893 | 175 } |
32881 | 176 } |
177 | |
34684 | 178 /* reload menu window */ |
23077 | 179 |
33555 | 180 if (prev && guiApp.menuIsPresent) { |
181 free(menuDrawBuffer); | |
182 menuDrawBuffer = calloc(1, guiApp.menu.Bitmap.ImageSize); | |
32881 | 183 |
33555 | 184 if (!menuDrawBuffer) { |
33530 | 185 gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_NEMDB); |
33768 | 186 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
32881 | 187 } |
23077 | 188 |
33555 | 189 wsResizeWindow(&guiApp.menuWindow, guiApp.menu.width, guiApp.menu.height); |
190 wsResizeImage(&guiApp.menuWindow, guiApp.menu.width, guiApp.menu.height); | |
191 wsSetShape(&guiApp.menuWindow, guiApp.menu.Mask.Image); | |
192 wsVisibleWindow(&guiApp.menuWindow, wsHideWindow); | |
32881 | 193 } else |
33555 | 194 uiMenuInit(); |
32881 | 195 |
34697 | 196 /* reload video window */ |
23077 | 197 |
34697 | 198 if (guiApp.video.Bitmap.Image) |
199 wsResizeImage(&guiApp.videoWindow, guiApp.video.Bitmap.Width, guiApp.video.Bitmap.Height); | |
32881 | 200 |
34697 | 201 if (!guiApp.videoWindow.isFullScreen && !guiInfo.Playing) { |
202 wsResizeWindow(&guiApp.videoWindow, guiApp.video.width, guiApp.video.height); | |
203 wsMoveWindow(&guiApp.videoWindow, False, guiApp.video.x, guiApp.video.y); | |
32881 | 204 } |
205 | |
34697 | 206 if (guiApp.video.Bitmap.Image) |
207 wsConvert(&guiApp.videoWindow, guiApp.video.Bitmap.Image); | |
23077 | 208 |
33555 | 209 if (!guiInfo.Playing) { |
34697 | 210 uiVideoRender = 1; |
211 wsSetBackgroundRGB(&guiApp.videoWindow, guiApp.video.R, guiApp.video.G, guiApp.video.B); | |
35357
80fe9ad7f318
Pass guiApp's wsTWindow parameters always by reference (if possible).
ib
parents:
34697
diff
changeset
|
212 wsClearWindow(&guiApp.videoWindow); |
34697 | 213 wsPostRedisplay(&guiApp.videoWindow); |
32881 | 214 } |
215 | |
34684 | 216 /* reload playbar */ |
32881 | 217 |
218 if (bprev) | |
33555 | 219 wsDestroyWindow(&guiApp.playbarWindow); |
32881 | 220 |
33555 | 221 uiPlaybarInit(); |
23077 | 222 |
34684 | 223 /* reload main window */ |
32881 | 224 |
33555 | 225 free(mainDrawBuffer); |
226 mainDrawBuffer = calloc(1, guiApp.main.Bitmap.ImageSize); | |
23077 | 227 |
33555 | 228 if (!mainDrawBuffer) { |
33530 | 229 gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_NEMDB); |
33768 | 230 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
32881 | 231 } |
23077 | 232 |
33555 | 233 wsDestroyWindow(&guiApp.mainWindow); |
32881 | 234 |
33555 | 235 wsCreateWindow(&guiApp.mainWindow, guiApp.main.x, guiApp.main.y, guiApp.main.width, guiApp.main.height, wsNoBorder, wsShowMouseCursor | wsHandleMouseButton | wsHandleMouseMove, wsShowFrame | wsMaxSize | wsHideWindow, "MPlayer"); |
236 wsCreateImage(&guiApp.mainWindow, guiApp.main.Bitmap.Width, guiApp.main.Bitmap.Height); | |
237 wsSetShape(&guiApp.mainWindow, guiApp.main.Mask.Image); | |
238 wsSetIcon(wsDisplay, guiApp.mainWindow.WindowID, &guiIcon); | |
23077 | 239 |
33555 | 240 guiApp.mainWindow.ReDraw = (void *)uiMainDraw; |
241 guiApp.mainWindow.MouseHandler = uiMainMouseHandle; | |
242 guiApp.mainWindow.KeyHandler = uiMainKeyHandle; | |
243 guiApp.mainWindow.DandDHandler = uiDandDHandler; | |
32881 | 244 |
33555 | 245 wsXDNDMakeAwareness(&guiApp.mainWindow); |
23077 | 246 |
33555 | 247 if (!guiApp.mainDecoration) |
248 wsWindowDecoration(&guiApp.mainWindow, 0); | |
32881 | 249 |
33555 | 250 wsVisibleWindow(&guiApp.mainWindow, wsShowWindow); |
32881 | 251 mainVisible = 1; |
252 | |
33555 | 253 btnModify(evSetVolume, guiInfo.Volume); |
254 btnModify(evSetBalance, guiInfo.Balance); | |
255 btnModify(evSetMoviePosition, guiInfo.Position); | |
34697 | 256 btnSet(evFullScreen, (guiApp.videoWindow.isFullScreen ? btnPressed : btnReleased)); |
23077 | 257 |
34697 | 258 wsSetLayer(wsDisplay, guiApp.mainWindow.WindowID, guiApp.videoWindow.isFullScreen); |
259 wsSetLayer(wsDisplay, guiApp.menuWindow.WindowID, guiApp.videoWindow.isFullScreen); | |
32881 | 260 } |
261 | |
35437 | 262 /** |
35452 | 263 * @brief Set the file to be played. |
35437 | 264 * |
265 * @param dir directory (optional, else NULL) | |
266 * @param name filename | |
267 * @param type stream type of the file | |
268 */ | |
35452 | 269 void uiSetFile(char *dir, char *name, int type) |
32881 | 270 { |
271 if (!dir) | |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
272 setdup(&guiInfo.Filename, name); |
32881 | 273 else |
33740
2c02269701bd
Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents:
33739
diff
changeset
|
274 setddup(&guiInfo.Filename, dir, name); |
23077 | 275 |
34064 | 276 filename = guiInfo.Filename; |
34399
f2c03009068d
Don't explicitly set stream type if the type doesn't change.
ib
parents:
34387
diff
changeset
|
277 |
f2c03009068d
Don't explicitly set stream type if the type doesn't change.
ib
parents:
34387
diff
changeset
|
278 if (type != SAME_STREAMTYPE) |
34400 | 279 guiInfo.StreamType = type; |
34064 | 280 |
33897 | 281 nfree(guiInfo.AudioFilename); |
282 nfree(guiInfo.SubtitleFilename); | |
23077 | 283 } |
284 | |
35437 | 285 /** |
286 * @brief Set file to be played to current playlist entry. | |
287 */ | |
33555 | 288 void uiCurr(void) |
23077 | 289 { |
32881 | 290 plItem *curr; |
23077 | 291 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
292 if (guiInfo.Playing == GUI_PAUSE) |
32881 | 293 return; |
23077 | 294 |
33555 | 295 switch (guiInfo.StreamType) { |
34387 | 296 case STREAMTYPE_CDDA: |
34077 | 297 case STREAMTYPE_VCD: |
298 case STREAMTYPE_DVD: | |
35433 | 299 |
32881 | 300 break; |
301 | |
302 default: | |
303 | |
34663 | 304 curr = listMgr(PLAYLIST_ITEM_GET_CURR, 0); |
32881 | 305 |
306 if (curr) { | |
35452 | 307 uiSetFile(curr->path, curr->name, STREAMTYPE_FILE); |
35430
2d55540614a9
Move uiProcessNextInPlaylist to the guiInfo structure.
ib
parents:
35429
diff
changeset
|
308 guiInfo.PlaylistNext = 0; |
32881 | 309 break; |
310 } | |
311 | |
312 return; | |
313 } | |
314 | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
315 if (guiInfo.Playing == GUI_PLAY) |
33555 | 316 uiEventHandling(evPlay, 0); |
23077 | 317 } |
318 | |
35437 | 319 /** |
320 * @brief Switch to previous playback track. | |
321 */ | |
33555 | 322 void uiPrev(void) |
23077 | 323 { |
35426 | 324 int stop = 0; |
32881 | 325 plItem *prev; |
326 | |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
327 if (guiInfo.Playing == GUI_PAUSE) |
32881 | 328 return; |
329 | |
33555 | 330 switch (guiInfo.StreamType) { |
34387 | 331 case STREAMTYPE_CDDA: |
35426 | 332 |
34387 | 333 if (--guiInfo.Track == 0) { |
334 guiInfo.Track = 1; | |
335 stop = 1; | |
336 } | |
35426 | 337 |
34387 | 338 break; |
339 | |
34077 | 340 case STREAMTYPE_VCD: |
35426 | 341 |
34077 | 342 if (--guiInfo.Track == 1) { |
343 guiInfo.Track = 2; | |
344 stop = 1; | |
345 } | |
35426 | 346 |
34077 | 347 break; |
348 | |
32881 | 349 case STREAMTYPE_DVD: |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
350 |
33876
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
351 if (--guiInfo.Chapter == 0) { |
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
352 guiInfo.Chapter = 1; |
32881 | 353 |
35428 | 354 if (--guiInfo.Track == 0) { |
33876
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
355 guiInfo.Track = 1; |
32881 | 356 stop = 1; |
357 } | |
358 } | |
359 | |
360 break; | |
361 | |
362 default: | |
363 | |
34663 | 364 prev = listMgr(PLAYLIST_ITEM_GET_PREV, 0); |
32881 | 365 |
366 if (prev) { | |
35452 | 367 uiSetFile(prev->path, prev->name, STREAMTYPE_FILE); |
35430
2d55540614a9
Move uiProcessNextInPlaylist to the guiInfo structure.
ib
parents:
35429
diff
changeset
|
368 guiInfo.PlaylistNext = (guiInfo.Playing ? 0 : 1); |
33898 | 369 guiInfo.Track--; |
32881 | 370 break; |
371 } | |
372 | |
373 return; | |
374 } | |
375 | |
376 if (stop) | |
33555 | 377 uiEventHandling(evStop, 0); |
32881 | 378 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
379 if (guiInfo.Playing == GUI_PLAY) |
33555 | 380 uiEventHandling(evPlay, 0); |
23077 | 381 } |
382 | |
35437 | 383 /** |
384 * @brief Switch to next playback track. | |
385 */ | |
33555 | 386 void uiNext(void) |
23077 | 387 { |
32881 | 388 int stop = 0; |
389 plItem *next; | |
23077 | 390 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
391 if (guiInfo.Playing == GUI_PAUSE) |
32881 | 392 return; |
393 | |
33555 | 394 switch (guiInfo.StreamType) { |
34387 | 395 case STREAMTYPE_CDDA: |
35425 | 396 case STREAMTYPE_VCD: |
34387 | 397 |
398 if (++guiInfo.Track > guiInfo.Tracks) { | |
399 guiInfo.Track = guiInfo.Tracks; | |
400 stop = 1; | |
401 } | |
402 | |
403 break; | |
404 | |
32881 | 405 case STREAMTYPE_DVD: |
406 | |
33876
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
407 if (guiInfo.Chapter++ == guiInfo.Chapters) { |
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
408 guiInfo.Chapter = 1; |
32881 | 409 |
33876
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
410 if (++guiInfo.Track > guiInfo.Tracks) { |
4789b8eed97e
Get rid of a bunch of needless or redundant guiInfo members.
ib
parents:
33874
diff
changeset
|
411 guiInfo.Track = guiInfo.Tracks; |
32881 | 412 stop = 1; |
413 } | |
414 } | |
415 | |
416 break; | |
417 | |
418 default: | |
419 | |
34663 | 420 next = listMgr(PLAYLIST_ITEM_GET_NEXT, 0); |
32881 | 421 |
422 if (next) { | |
35452 | 423 uiSetFile(next->path, next->name, STREAMTYPE_FILE); |
35430
2d55540614a9
Move uiProcessNextInPlaylist to the guiInfo structure.
ib
parents:
35429
diff
changeset
|
424 guiInfo.PlaylistNext = (guiInfo.Playing ? 0 : 1); |
33898 | 425 guiInfo.Track++; |
32881 | 426 break; |
427 } | |
428 | |
429 return; | |
430 } | |
431 | |
432 if (stop) | |
33555 | 433 uiEventHandling(evStop, 0); |
32881 | 434 |
33615
1f9a31d4f114
Replace all playback integer constants by their symbolic constants.
ib
parents:
33614
diff
changeset
|
435 if (guiInfo.Playing == GUI_PLAY) |
33555 | 436 uiEventHandling(evPlay, 0); |
23077 | 437 } |