Mercurial > mplayer.hg
annotate gui/ui/main.c @ 36914:1db578946152
Add new dynamic label variable $D.
This is the balance without decimal places (which makes more sense to me
than $B and should have been the output of $B in the first place).
author | ib |
---|---|
date | Thu, 13 Mar 2014 15:41:22 +0000 |
parents | 97a16ac7f8dd |
children | 40ad45360c8a |
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 |
34699
ed0e00db4306
Cosmetic: Move, change and add some comments on GUI windows.
ib
parents:
34697
diff
changeset
|
19 /* main window */ |
ed0e00db4306
Cosmetic: Move, change and add some comments on GUI windows.
ib
parents:
34697
diff
changeset
|
20 |
23077 | 21 #include <stdlib.h> |
22 #include <stdio.h> | |
23 #include <sys/stat.h> | |
24 #include <unistd.h> | |
23305
22d3d12c6dfb
Include string.h for memcpy, fastmemcpy.h alone is not enough.
reimar
parents:
23154
diff
changeset
|
25 #include <string.h> |
23077 | 26 |
35528 | 27 #include "ui.h" |
35525 | 28 #include "gui/app/app.h" |
29 #include "gui/app/gui.h" | |
33738 | 30 #include "gui/interface.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
31 #include "gui/skin/font.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
32 #include "gui/skin/skin.h" |
33742
e1539e14d60f
Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents:
33739
diff
changeset
|
33 #include "gui/util/list.h" |
33739 | 34 #include "gui/util/mem.h" |
33737 | 35 #include "gui/util/string.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
36 #include "gui/wm/ws.h" |
35789 | 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" |
34174
a93891202051
Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents:
34077
diff
changeset
|
40 #include "mp_msg.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
41 #include "libvo/x11_common.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
42 #include "libvo/fastmemcpy.h" |
33531
84ce059fae34
Get non-multimedia X11 key definitions from libvo/wskeys.h.
ib
parents:
33525
diff
changeset
|
43 #include "libvo/wskeys.h" |
23077 | 44 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
45 #include "stream/stream.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
46 #include "stream/url.h" |
23077 | 47 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
48 #include "libmpdemux/demuxer.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
49 #include "libmpdemux/stheader.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
50 #include "codec-cfg.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
51 #include "m_option.h" |
30516 | 52 #include "mp_core.h" |
35545 | 53 #include "libavutil/common.h" |
23077 | 54 |
33556 | 55 #include "actions.h" |
23077 | 56 |
35795 | 57 static unsigned char * mainDrawBuffer; |
35771 | 58 int uiMainRender = True; |
23077 | 59 |
35493 | 60 int mainVisible = True; |
23077 | 61 |
35493 | 62 int boxMoved = False; |
23077 | 63 int sx = 0,sy = 0; |
64 int i,pot = 0; | |
65 | |
33556 | 66 #include "render.h" |
23077 | 67 |
35780 | 68 static void uiMainDraw( void ) |
23077 | 69 { |
70 | |
33768 | 71 if ( guiApp.mainWindow.State == wsWindowClosed ) mplayer( MPLAYER_EXIT_GUI, EXIT_QUIT, 0 ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
72 |
33555 | 73 if ( guiApp.mainWindow.Visible == wsWindowNotVisible || |
23077 | 74 !mainVisible ) return; |
33555 | 75 // !guiApp.mainWindow.Mapped ) return; |
23077 | 76 |
33555 | 77 if ( uiMainRender && guiApp.mainWindow.State == wsWindowExpose ) |
23077 | 78 { |
33555 | 79 btnModify( evSetMoviePosition,guiInfo.Position ); |
80 btnModify( evSetVolume,guiInfo.Volume ); | |
23077 | 81 |
33555 | 82 fast_memcpy( mainDrawBuffer,guiApp.main.Bitmap.Image,guiApp.main.Bitmap.ImageSize ); |
83 RenderAll( &guiApp.mainWindow,guiApp.mainItems,guiApp.IndexOfMainItems,mainDrawBuffer ); | |
35493 | 84 uiMainRender=False; |
23077 | 85 } |
35746 | 86 // NOTE TO MYSELF: probably not, if uiMainRender is False |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
87 wsImageDraw( &guiApp.mainWindow ); |
23077 | 88 // XFlush( wsDisplay ); |
89 } | |
90 | |
35780 | 91 static void uiMainMouse( int Button,int X,int Y,int RX,int RY ) |
23077 | 92 { |
93 static int itemtype = 0; | |
94 int i; | |
35688 | 95 guiItem * item = NULL; |
23077 | 96 float value = 0.0f; |
97 | |
98 static int SelectedItem = -1; | |
99 int currentselected = -1; | |
100 | |
33555 | 101 for ( i=0;i <= guiApp.IndexOfMainItems;i++ ) |
102 if ( ( guiApp.mainItems[i].pressed != btnDisabled )&& | |
35675 | 103 ( isInside( X,Y,guiApp.mainItems[i].x,guiApp.mainItems[i].y,guiApp.mainItems[i].x+guiApp.mainItems[i].width,guiApp.mainItems[i].y+guiApp.mainItems[i].height ) ) ) |
23077 | 104 { currentselected=i; break; } |
105 | |
106 switch ( Button ) | |
107 { | |
108 case wsPMMouseButton: | |
34333 | 109 gtkShow( ivHidePopUpMenu,NULL ); |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35763
diff
changeset
|
110 uiMenuShow( RX,RY ); |
23077 | 111 itemtype=itPRMButton; |
112 break; | |
113 case wsRMMouseButton: | |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35763
diff
changeset
|
114 uiMenuHide( RX,RY,0 ); |
23077 | 115 break; |
116 | |
117 case wsPLMouseButton: | |
34333 | 118 gtkShow( ivHidePopUpMenu,NULL ); |
35493 | 119 sx=X; sy=Y; boxMoved=True; itemtype=itPLMButton; |
23077 | 120 SelectedItem=currentselected; |
121 if ( SelectedItem == -1 ) break; | |
35493 | 122 boxMoved=False; |
33555 | 123 item=&guiApp.mainItems[SelectedItem]; |
23077 | 124 itemtype=item->type; |
125 item->pressed=btnPressed; | |
35807 | 126 // NOTE TO MYSELF: commented, because the expression can never be true |
127 /*switch( item->type ) | |
23077 | 128 { |
129 case itButton: | |
130 if ( ( SelectedItem > -1 ) && | |
32911 | 131 ( ( ( item->message == evPlaySwitchToPause && item->message == evPauseSwitchToPlay ) ) || |
132 ( ( item->message == evPauseSwitchToPlay && item->message == evPlaySwitchToPause ) ) ) ) | |
23077 | 133 { item->pressed=btnDisabled; } |
134 break; | |
35807 | 135 }*/ |
23077 | 136 break; |
137 case wsRLMouseButton: | |
35493 | 138 boxMoved=False; |
33107 | 139 if ( SelectedItem != -1 ) // NOTE TO MYSELF: only if itButton, itHPotmeter or itVPotmeter |
140 { | |
33555 | 141 item=&guiApp.mainItems[SelectedItem]; |
33108 | 142 item->pressed=btnReleased; |
33107 | 143 } |
35351 | 144 if ( currentselected == - 1 || SelectedItem == -1 ) { itemtype=0; break; } |
23077 | 145 SelectedItem=-1; |
146 value=0; | |
147 switch( itemtype ) | |
148 { | |
149 case itPotmeter: | |
150 case itHPotmeter: | |
36900 | 151 btnModify( item->message,100.0 * ( X - item->x ) / item->width ); |
35773 | 152 uiEvent( item->message,item->value ); |
23077 | 153 value=item->value; |
154 break; | |
155 case itVPotmeter: | |
36900 | 156 btnModify( item->message,100.0 - 100.0 * ( Y - item->y ) / item->height ); |
35773 | 157 uiEvent( item->message,item->value ); |
23077 | 158 value=item->value; |
159 break; | |
160 } | |
35773 | 161 uiEvent( item->message,value ); |
23077 | 162 itemtype=0; |
163 break; | |
164 | |
165 case wsRRMouseButton: | |
34333 | 166 gtkShow( ivShowPopUpMenu,NULL ); |
23077 | 167 break; |
168 | |
34684 | 169 /* rolled mouse ... de szar :))) */ |
23077 | 170 case wsP5MouseButton: value=-2.5f; goto rollerhandled; |
171 case wsP4MouseButton: value= 2.5f; | |
172 rollerhandled: | |
35365 | 173 if (currentselected != - 1) |
174 { | |
35366 | 175 item=&guiApp.mainItems[currentselected]; |
176 if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itPotmeter ) ) | |
177 { | |
178 item->value+=value; | |
179 btnModify( item->message,item->value ); | |
35773 | 180 uiEvent( item->message,item->value ); |
35366 | 181 } |
35365 | 182 } |
23077 | 183 break; |
184 | |
34684 | 185 /* moving */ |
23077 | 186 case wsMoveMouse: |
33555 | 187 item=&guiApp.mainItems[SelectedItem]; |
23077 | 188 switch ( itemtype ) |
189 { | |
190 case itPLMButton: | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
191 wsWindowMove( &guiApp.mainWindow,True,RX - abs( sx ),RY - abs( sy ) ); |
23077 | 192 break; |
193 case itPRMButton: | |
35779 | 194 if (guiApp.menuIsPresent) guiApp.menuWindow.MouseHandler( 0,RX,RY,0,0 ); |
23077 | 195 break; |
196 case itVPotmeter: | |
36900 | 197 item->value=100.0 - 100.0 * ( Y - item->y ) / item->height; |
23077 | 198 goto potihandled; |
36901 | 199 case itPotmeter: |
23077 | 200 case itHPotmeter: |
36900 | 201 item->value=100.0 * ( X - item->x ) / item->width; |
23077 | 202 potihandled: |
203 if ( item->value > 100.0f ) item->value=100.0f; | |
204 if ( item->value < 0.0f ) item->value=0.0f; | |
35773 | 205 uiEvent( item->message,item->value ); |
23077 | 206 break; |
207 } | |
208 break; | |
209 } | |
210 } | |
211 | |
35780 | 212 static void uiMainKey( int KeyCode,int Type,int Key ) |
23077 | 213 { |
214 int msg = evNone; | |
215 | |
216 if ( Type != wsKeyPressed ) return; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
217 |
23077 | 218 if ( !Key ) |
219 { | |
220 switch ( KeyCode ) | |
221 { | |
33524 | 222 // NOTE TO MYSELF: This is only for the Acer AirKey V keyboard. |
33536
fc1402410163
Remove support for Acer AirKey V keyboard multimedia keys.
ib
parents:
33535
diff
changeset
|
223 /*case wsXFMMPrev: msg=evPrev; break; |
23077 | 224 case wsXFMMStop: msg=evStop; break; |
225 case wsXFMMPlay: msg=evPlaySwitchToPause; break; | |
226 case wsXFMMNext: msg=evNext; break; | |
227 case wsXFMMVolUp: msg=evIncVolume; break; | |
228 case wsXFMMVolDown: msg=evDecVolume; break; | |
33536
fc1402410163
Remove support for Acer AirKey V keyboard multimedia keys.
ib
parents:
33535
diff
changeset
|
229 case wsXFMMMute: msg=evMute; break;*/ |
23077 | 230 } |
231 } | |
232 else | |
233 { | |
234 switch ( Key ) | |
235 { | |
236 case wsEnter: msg=evPlay; break; | |
237 case wsXF86LowerVolume: msg=evDecVolume; break; | |
238 case wsXF86RaiseVolume: msg=evIncVolume; break; | |
239 case wsXF86Mute: msg=evMute; break; | |
33525 | 240 case wsXF86Pause: |
23077 | 241 case wsXF86Play: msg=evPlaySwitchToPause; break; |
242 case wsXF86Stop: msg=evStop; break; | |
243 case wsXF86Prev: msg=evPrev; break; | |
244 case wsXF86Next: msg=evNext; break; | |
245 case wsXF86Media: msg=evLoad; break; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
246 case wsEscape: |
34697 | 247 if ( guiInfo.VideoWindow && guiInfo.Playing && guiApp.videoWindow.isFullScreen ) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
248 { |
35773 | 249 uiEvent( evNormalSize,0 ); |
23077 | 250 return; |
251 } | |
252 default: vo_x11_putkey( Key ); return; | |
253 } | |
254 } | |
35773 | 255 if ( msg != evNone ) uiEvent( msg,0 ); |
23077 | 256 } |
257 | |
35759 | 258 /* this will be used to handle drag & drop files */ |
35780 | 259 static void uiMainDND(int num,char** files) |
23077 | 260 { |
261 struct stat buf; | |
262 int f = 0; | |
263 | |
264 char* subtitles = NULL; | |
35521 | 265 char* file = NULL; |
35384 | 266 char* s; |
23077 | 267 |
268 if (num <= 0) | |
269 return; | |
270 | |
271 | |
272 /* now fill it with new items */ | |
273 for(f=0; f < num; f++){ | |
274 char* str = strdup( files[f] ); | |
275 plItem* item; | |
276 | |
24086
f5b32d12b691
remove gconvert_uri_to_filename() and use url_unescape_string() instead.
iive
parents:
23457
diff
changeset
|
277 url_unescape_string(str, files[f]); |
23077 | 278 |
279 if(stat(str,&buf) == 0 && S_ISDIR(buf.st_mode) == 0) { | |
280 /* this is not a directory so try to play it */ | |
281 mp_msg( MSGT_GPLAYER,MSGL_V,"Received D&D %s\n",str ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
282 |
23077 | 283 /* check if it is a subtitle file */ |
284 { | |
285 char* ext = strrchr(str,'.'); | |
286 if (ext) { | |
287 static char supported[] = "utf/sub/srt/smi/rt//txt/ssa/aqt/"; | |
288 char* type; | |
289 int len; | |
290 if((len=strlen(++ext)) && (type=strstr(supported,ext)) &&\ | |
291 (type-supported)%4 == 0 && *(type+len) == '/'){ | |
292 /* handle subtitle file */ | |
33739 | 293 nfree(subtitles); |
23077 | 294 subtitles = str; |
295 continue; | |
296 } | |
297 } | |
298 } | |
299 | |
300 /* clear playlist */ | |
35521 | 301 if (file == NULL) { |
302 file = files[f]; | |
34663 | 303 listMgr(PLAYLIST_DELETE,0); |
23077 | 304 } |
305 | |
306 item = calloc(1,sizeof(plItem)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
307 |
35384 | 308 s = strrchr( str,'/' ); |
309 | |
23077 | 310 /* FIXME: decompose file name ? */ |
311 /* yes -- Pontscho */ | |
35384 | 312 if ( s ) { |
313 *s=0; s++; | |
23077 | 314 item->name = gstrdup( s ); |
315 item->path = gstrdup( str ); | |
316 } else { | |
35385 | 317 // NOTE TO MYSELF: this shouldn't happen, make sure we have a full path |
23077 | 318 item->name = strdup(str); |
35385 | 319 item->path = strdup("."); |
23077 | 320 } |
34681 | 321 listMgr(PLAYLIST_ITEM_APPEND,item); |
23077 | 322 } else { |
36694 | 323 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_GUI_MSG_NotAFile1,str ); |
23077 | 324 } |
325 free( str ); | |
326 } | |
327 | |
35521 | 328 if (file) { |
329 uiSetFile( NULL,file,STREAMTYPE_FILE ); | |
35773 | 330 if ( guiInfo.Playing == GUI_PLAY ) uiEvent( evStop,0 ); |
331 uiEvent( evPlay,0 ); | |
23077 | 332 } |
333 if (subtitles) { | |
33897 | 334 nfree(guiInfo.SubtitleFilename); |
335 guiInfo.SubtitleFilename = subtitles; | |
336 mplayerLoadSubtitle(guiInfo.SubtitleFilename); | |
23077 | 337 } |
338 } | |
35780 | 339 |
340 void uiMainInit (void) | |
341 { | |
35789 | 342 mainDrawBuffer = malloc(guiApp.main.Bitmap.ImageSize); |
343 | |
344 if (!mainDrawBuffer) | |
345 { | |
36694 | 346 gmp_msg(MSGT_GPLAYER, MSGL_FATAL, "[main] " MSGTR_GUI_MSG_MemoryErrorWindow); |
35789 | 347 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
348 } | |
349 | |
36053 | 350 wsWindowCreate(&guiApp.mainWindow, guiApp.main.x, guiApp.main.y, guiApp.main.width, guiApp.main.height, (guiApp.mainDecoration ? wsShowFrame : 0 ) | wsMinSize | wsMaxSize | wsHideWindow, wsShowMouseCursor | wsHandleMouseButton | wsHandleMouseMove, MPlayer); |
35789 | 351 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[main] mainWindow ID: 0x%x\n", (int) guiApp.mainWindow.WindowID); |
352 wsWindowShape(&guiApp.mainWindow, guiApp.main.Mask.Image); | |
353 wsWindowIcon(wsDisplay, guiApp.mainWindow.WindowID, &guiIcon); | |
354 wsXDNDMakeAwareness(&guiApp.mainWindow); | |
355 | |
35780 | 356 guiApp.mainWindow.DrawHandler = uiMainDraw; |
357 guiApp.mainWindow.MouseHandler = uiMainMouse; | |
358 guiApp.mainWindow.KeyHandler = uiMainKey; | |
359 guiApp.mainWindow.DNDHandler = uiMainDND; | |
360 } | |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
361 |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
362 void uiMainDone (void) |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
363 { |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
364 nfree(mainDrawBuffer); |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
365 wsWindowDestroy(&guiApp.mainWindow); |
36291 | 366 wsEvents(); |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
367 } |