Mercurial > mplayer.hg
annotate gui/ui/main.c @ 35780:4073fff5efc7
Add new functions uiMainInit() and uiVideoInit().
Relocate handler initialization stuff there
and reorder the windows init calls.
As a result, all handler functions can be static now.
author | ib |
---|---|
date | Fri, 25 Jan 2013 12:26:31 +0000 |
parents | 8ad72f9cf697 |
children | 9fdc3e22063f |
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" |
23077 | 37 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
38 #include "help_mp.h" |
34174
a93891202051
Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents:
34077
diff
changeset
|
39 #include "mp_msg.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
40 #include "libvo/x11_common.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
41 #include "libvo/fastmemcpy.h" |
33531
84ce059fae34
Get non-multimedia X11 key definitions from libvo/wskeys.h.
ib
parents:
33525
diff
changeset
|
42 #include "libvo/wskeys.h" |
23077 | 43 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
44 #include "stream/stream.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
45 #include "stream/url.h" |
23077 | 46 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
47 #include "libmpdemux/demuxer.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
48 #include "libmpdemux/stheader.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
49 #include "codec-cfg.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
50 #include "m_option.h" |
30516 | 51 #include "mp_core.h" |
35545 | 52 #include "libavutil/common.h" |
23077 | 53 |
33556 | 54 #include "actions.h" |
23077 | 55 |
33555 | 56 unsigned char * mainDrawBuffer = NULL; |
35771 | 57 int uiMainRender = True; |
23077 | 58 |
35493 | 59 int mainVisible = True; |
23077 | 60 |
35493 | 61 int boxMoved = False; |
23077 | 62 int sx = 0,sy = 0; |
63 int i,pot = 0; | |
64 | |
33556 | 65 #include "render.h" |
23077 | 66 |
35780 | 67 static void uiMainDraw( void ) |
23077 | 68 { |
69 | |
33768 | 70 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
|
71 |
33555 | 72 if ( guiApp.mainWindow.Visible == wsWindowNotVisible || |
23077 | 73 !mainVisible ) return; |
33555 | 74 // !guiApp.mainWindow.Mapped ) return; |
23077 | 75 |
33555 | 76 if ( uiMainRender && guiApp.mainWindow.State == wsWindowExpose ) |
23077 | 77 { |
33555 | 78 btnModify( evSetMoviePosition,guiInfo.Position ); |
79 btnModify( evSetVolume,guiInfo.Volume ); | |
23077 | 80 |
33555 | 81 fast_memcpy( mainDrawBuffer,guiApp.main.Bitmap.Image,guiApp.main.Bitmap.ImageSize ); |
82 RenderAll( &guiApp.mainWindow,guiApp.mainItems,guiApp.IndexOfMainItems,mainDrawBuffer ); | |
35493 | 83 uiMainRender=False; |
23077 | 84 } |
35746 | 85 // 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
|
86 wsImageDraw( &guiApp.mainWindow ); |
23077 | 87 // XFlush( wsDisplay ); |
88 } | |
89 | |
35780 | 90 static void uiMainMouse( int Button,int X,int Y,int RX,int RY ) |
23077 | 91 { |
92 static int itemtype = 0; | |
93 int i; | |
35688 | 94 guiItem * item = NULL; |
23077 | 95 float value = 0.0f; |
96 | |
97 static int SelectedItem = -1; | |
98 int currentselected = -1; | |
99 | |
33555 | 100 for ( i=0;i <= guiApp.IndexOfMainItems;i++ ) |
101 if ( ( guiApp.mainItems[i].pressed != btnDisabled )&& | |
35675 | 102 ( 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 | 103 { currentselected=i; break; } |
104 | |
105 switch ( Button ) | |
106 { | |
107 case wsPMMouseButton: | |
34333 | 108 gtkShow( ivHidePopUpMenu,NULL ); |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35763
diff
changeset
|
109 uiMenuShow( RX,RY ); |
23077 | 110 itemtype=itPRMButton; |
111 break; | |
112 case wsRMMouseButton: | |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35763
diff
changeset
|
113 uiMenuHide( RX,RY,0 ); |
23077 | 114 break; |
115 | |
116 case wsPLMouseButton: | |
34333 | 117 gtkShow( ivHidePopUpMenu,NULL ); |
35493 | 118 sx=X; sy=Y; boxMoved=True; itemtype=itPLMButton; |
23077 | 119 SelectedItem=currentselected; |
120 if ( SelectedItem == -1 ) break; | |
35493 | 121 boxMoved=False; |
33555 | 122 item=&guiApp.mainItems[SelectedItem]; |
23077 | 123 itemtype=item->type; |
124 item->pressed=btnPressed; | |
125 switch( item->type ) | |
126 { | |
127 case itButton: | |
128 if ( ( SelectedItem > -1 ) && | |
32911 | 129 ( ( ( item->message == evPlaySwitchToPause && item->message == evPauseSwitchToPlay ) ) || |
130 ( ( item->message == evPauseSwitchToPlay && item->message == evPlaySwitchToPause ) ) ) ) | |
23077 | 131 { item->pressed=btnDisabled; } |
132 break; | |
133 } | |
134 break; | |
135 case wsRLMouseButton: | |
35493 | 136 boxMoved=False; |
33107 | 137 if ( SelectedItem != -1 ) // NOTE TO MYSELF: only if itButton, itHPotmeter or itVPotmeter |
138 { | |
33555 | 139 item=&guiApp.mainItems[SelectedItem]; |
33108 | 140 item->pressed=btnReleased; |
33107 | 141 } |
35351 | 142 if ( currentselected == - 1 || SelectedItem == -1 ) { itemtype=0; break; } |
23077 | 143 SelectedItem=-1; |
144 value=0; | |
145 switch( itemtype ) | |
146 { | |
147 case itPotmeter: | |
148 case itHPotmeter: | |
32911 | 149 btnModify( item->message,(float)( X - item->x ) / item->width * 100.0f ); |
35773 | 150 uiEvent( item->message,item->value ); |
23077 | 151 value=item->value; |
152 break; | |
153 case itVPotmeter: | |
32911 | 154 btnModify( item->message, ( 1. - (float)( Y - item->y ) / item->height) * 100.0f ); |
35773 | 155 uiEvent( item->message,item->value ); |
23077 | 156 value=item->value; |
157 break; | |
158 } | |
35773 | 159 uiEvent( item->message,value ); |
23077 | 160 itemtype=0; |
161 break; | |
162 | |
163 case wsRRMouseButton: | |
34333 | 164 gtkShow( ivShowPopUpMenu,NULL ); |
23077 | 165 break; |
166 | |
34684 | 167 /* rolled mouse ... de szar :))) */ |
23077 | 168 case wsP5MouseButton: value=-2.5f; goto rollerhandled; |
169 case wsP4MouseButton: value= 2.5f; | |
170 rollerhandled: | |
35365 | 171 if (currentselected != - 1) |
172 { | |
35366 | 173 item=&guiApp.mainItems[currentselected]; |
174 if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itPotmeter ) ) | |
175 { | |
176 item->value+=value; | |
177 btnModify( item->message,item->value ); | |
35773 | 178 uiEvent( item->message,item->value ); |
35366 | 179 } |
35365 | 180 } |
23077 | 181 break; |
182 | |
34684 | 183 /* moving */ |
23077 | 184 case wsMoveMouse: |
33555 | 185 item=&guiApp.mainItems[SelectedItem]; |
23077 | 186 switch ( itemtype ) |
187 { | |
188 case itPLMButton: | |
35681
80c5c89f77d6
Cosmetic: Rename ws functions for the sake of consistency.
ib
parents:
35675
diff
changeset
|
189 wsWindowMove( &guiApp.mainWindow,True,RX - abs( sx ),RY - abs( sy ) ); |
23077 | 190 break; |
191 case itPRMButton: | |
35779 | 192 if (guiApp.menuIsPresent) guiApp.menuWindow.MouseHandler( 0,RX,RY,0,0 ); |
23077 | 193 break; |
194 case itPotmeter: | |
195 item->value=(float)( X - item->x ) / item->width * 100.0f; | |
196 goto potihandled; | |
197 case itVPotmeter: | |
198 item->value=(1. - (float)( Y - item->y ) / item->height) * 100.0f; | |
199 goto potihandled; | |
200 case itHPotmeter: | |
201 item->value=(float)( X - item->x ) / item->width * 100.0f; | |
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 { |
323 mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_NotAFile,str ); | |
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 { | |
342 guiApp.mainWindow.DrawHandler = uiMainDraw; | |
343 guiApp.mainWindow.MouseHandler = uiMainMouse; | |
344 guiApp.mainWindow.KeyHandler = uiMainKey; | |
345 guiApp.mainWindow.DNDHandler = uiMainDND; | |
346 } |