Mercurial > mplayer.hg
annotate gui/ui/main.c @ 36679:36cbede21428
Fix bug with unicode font loading for font.desc files.
Unicode glyphs might not get loaded even if they are requested and
available.
Fix it by checking the font encoding rather than the subtitle encoding
when loading the font.
author | ib |
---|---|
date | Sat, 01 Feb 2014 16:57:50 +0000 |
parents | 7d250553d451 |
children | eed2fb870f43 |
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: | |
36283
ebbd9730a8c6
Increase precision of calculation by using constants of type double.
ib
parents:
36281
diff
changeset
|
151 btnModify( item->message,(float)( X - item->x ) / item->width * 100.0 ); |
35773 | 152 uiEvent( item->message,item->value ); |
23077 | 153 value=item->value; |
154 break; | |
155 case itVPotmeter: | |
36283
ebbd9730a8c6
Increase precision of calculation by using constants of type double.
ib
parents:
36281
diff
changeset
|
156 btnModify( item->message, ( 1.0 - (float)( Y - item->y ) / item->height) * 100.0 ); |
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 itPotmeter: | |
36283
ebbd9730a8c6
Increase precision of calculation by using constants of type double.
ib
parents:
36281
diff
changeset
|
197 item->value=(float)( X - item->x ) / item->width * 100.0; |
23077 | 198 goto potihandled; |
199 case itVPotmeter: | |
36283
ebbd9730a8c6
Increase precision of calculation by using constants of type double.
ib
parents:
36281
diff
changeset
|
200 item->value=(1.0 - (float)( Y - item->y ) / item->height) * 100.0; |
23077 | 201 goto potihandled; |
202 case itHPotmeter: | |
36283
ebbd9730a8c6
Increase precision of calculation by using constants of type double.
ib
parents:
36281
diff
changeset
|
203 item->value=(float)( X - item->x ) / item->width * 100.0; |
23077 | 204 potihandled: |
205 if ( item->value > 100.0f ) item->value=100.0f; | |
206 if ( item->value < 0.0f ) item->value=0.0f; | |
35773 | 207 uiEvent( item->message,item->value ); |
23077 | 208 break; |
209 } | |
210 break; | |
211 } | |
212 } | |
213 | |
35780 | 214 static void uiMainKey( int KeyCode,int Type,int Key ) |
23077 | 215 { |
216 int msg = evNone; | |
217 | |
218 if ( Type != wsKeyPressed ) return; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
219 |
23077 | 220 if ( !Key ) |
221 { | |
222 switch ( KeyCode ) | |
223 { | |
33524 | 224 // 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
|
225 /*case wsXFMMPrev: msg=evPrev; break; |
23077 | 226 case wsXFMMStop: msg=evStop; break; |
227 case wsXFMMPlay: msg=evPlaySwitchToPause; break; | |
228 case wsXFMMNext: msg=evNext; break; | |
229 case wsXFMMVolUp: msg=evIncVolume; break; | |
230 case wsXFMMVolDown: msg=evDecVolume; break; | |
33536
fc1402410163
Remove support for Acer AirKey V keyboard multimedia keys.
ib
parents:
33535
diff
changeset
|
231 case wsXFMMMute: msg=evMute; break;*/ |
23077 | 232 } |
233 } | |
234 else | |
235 { | |
236 switch ( Key ) | |
237 { | |
238 case wsEnter: msg=evPlay; break; | |
239 case wsXF86LowerVolume: msg=evDecVolume; break; | |
240 case wsXF86RaiseVolume: msg=evIncVolume; break; | |
241 case wsXF86Mute: msg=evMute; break; | |
33525 | 242 case wsXF86Pause: |
23077 | 243 case wsXF86Play: msg=evPlaySwitchToPause; break; |
244 case wsXF86Stop: msg=evStop; break; | |
245 case wsXF86Prev: msg=evPrev; break; | |
246 case wsXF86Next: msg=evNext; break; | |
247 case wsXF86Media: msg=evLoad; break; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
248 case wsEscape: |
34697 | 249 if ( guiInfo.VideoWindow && guiInfo.Playing && guiApp.videoWindow.isFullScreen ) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
250 { |
35773 | 251 uiEvent( evNormalSize,0 ); |
23077 | 252 return; |
253 } | |
254 default: vo_x11_putkey( Key ); return; | |
255 } | |
256 } | |
35773 | 257 if ( msg != evNone ) uiEvent( msg,0 ); |
23077 | 258 } |
259 | |
35759 | 260 /* this will be used to handle drag & drop files */ |
35780 | 261 static void uiMainDND(int num,char** files) |
23077 | 262 { |
263 struct stat buf; | |
264 int f = 0; | |
265 | |
266 char* subtitles = NULL; | |
35521 | 267 char* file = NULL; |
35384 | 268 char* s; |
23077 | 269 |
270 if (num <= 0) | |
271 return; | |
272 | |
273 | |
274 /* now fill it with new items */ | |
275 for(f=0; f < num; f++){ | |
276 char* str = strdup( files[f] ); | |
277 plItem* item; | |
278 | |
24086
f5b32d12b691
remove gconvert_uri_to_filename() and use url_unescape_string() instead.
iive
parents:
23457
diff
changeset
|
279 url_unescape_string(str, files[f]); |
23077 | 280 |
281 if(stat(str,&buf) == 0 && S_ISDIR(buf.st_mode) == 0) { | |
282 /* this is not a directory so try to play it */ | |
283 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
|
284 |
23077 | 285 /* check if it is a subtitle file */ |
286 { | |
287 char* ext = strrchr(str,'.'); | |
288 if (ext) { | |
289 static char supported[] = "utf/sub/srt/smi/rt//txt/ssa/aqt/"; | |
290 char* type; | |
291 int len; | |
292 if((len=strlen(++ext)) && (type=strstr(supported,ext)) &&\ | |
293 (type-supported)%4 == 0 && *(type+len) == '/'){ | |
294 /* handle subtitle file */ | |
33739 | 295 nfree(subtitles); |
23077 | 296 subtitles = str; |
297 continue; | |
298 } | |
299 } | |
300 } | |
301 | |
302 /* clear playlist */ | |
35521 | 303 if (file == NULL) { |
304 file = files[f]; | |
34663 | 305 listMgr(PLAYLIST_DELETE,0); |
23077 | 306 } |
307 | |
308 item = calloc(1,sizeof(plItem)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
309 |
35384 | 310 s = strrchr( str,'/' ); |
311 | |
23077 | 312 /* FIXME: decompose file name ? */ |
313 /* yes -- Pontscho */ | |
35384 | 314 if ( s ) { |
315 *s=0; s++; | |
23077 | 316 item->name = gstrdup( s ); |
317 item->path = gstrdup( str ); | |
318 } else { | |
35385 | 319 // NOTE TO MYSELF: this shouldn't happen, make sure we have a full path |
23077 | 320 item->name = strdup(str); |
35385 | 321 item->path = strdup("."); |
23077 | 322 } |
34681 | 323 listMgr(PLAYLIST_ITEM_APPEND,item); |
23077 | 324 } else { |
325 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_NotAFile,str ); | |
326 } | |
327 free( str ); | |
328 } | |
329 | |
35521 | 330 if (file) { |
331 uiSetFile( NULL,file,STREAMTYPE_FILE ); | |
35773 | 332 if ( guiInfo.Playing == GUI_PLAY ) uiEvent( evStop,0 ); |
333 uiEvent( evPlay,0 ); | |
23077 | 334 } |
335 if (subtitles) { | |
33897 | 336 nfree(guiInfo.SubtitleFilename); |
337 guiInfo.SubtitleFilename = subtitles; | |
338 mplayerLoadSubtitle(guiInfo.SubtitleFilename); | |
23077 | 339 } |
340 } | |
35780 | 341 |
342 void uiMainInit (void) | |
343 { | |
35789 | 344 mainDrawBuffer = malloc(guiApp.main.Bitmap.ImageSize); |
345 | |
346 if (!mainDrawBuffer) | |
347 { | |
36670 | 348 gmp_msg(MSGT_GPLAYER, MSGL_FATAL, "[main] " MSGTR_NEMDB); |
35789 | 349 mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0); |
350 } | |
351 | |
36053 | 352 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 | 353 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[main] mainWindow ID: 0x%x\n", (int) guiApp.mainWindow.WindowID); |
354 wsWindowShape(&guiApp.mainWindow, guiApp.main.Mask.Image); | |
355 wsWindowIcon(wsDisplay, guiApp.mainWindow.WindowID, &guiIcon); | |
356 wsXDNDMakeAwareness(&guiApp.mainWindow); | |
357 | |
35780 | 358 guiApp.mainWindow.DrawHandler = uiMainDraw; |
359 guiApp.mainWindow.MouseHandler = uiMainMouse; | |
360 guiApp.mainWindow.KeyHandler = uiMainKey; | |
361 guiApp.mainWindow.DNDHandler = uiMainDND; | |
362 } | |
35796
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 void uiMainDone (void) |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
365 { |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
366 nfree(mainDrawBuffer); |
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
367 wsWindowDestroy(&guiApp.mainWindow); |
36291 | 368 wsEvents(); |
35796
497a1c45a597
Add uiMainDone(), uiVideoDone(), uiPlaybarDone() and uiMenuDone().
ib
parents:
35795
diff
changeset
|
369 } |