Mercurial > mplayer.hg
annotate gui/ui/main.c @ 35771:07057fd75c51
Relocate uiMainEvent().
Move the code to actions.c, because it's general ui code
and not really related to the main window.
As a result, uiMainRender can't be static any longer.
Additionally, format moved code to MPlayer coding style.
author | ib |
---|---|
date | Fri, 25 Jan 2013 10:18:13 +0000 |
parents | 36f87d7432c7 |
children | c688b0dcbe66 |
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 |
35770 | 59 int uiLoadPlay = False; |
23077 | 60 |
35493 | 61 int mainVisible = True; |
23077 | 62 |
35493 | 63 int boxMoved = False; |
23077 | 64 int sx = 0,sy = 0; |
65 int i,pot = 0; | |
66 | |
33556 | 67 #include "render.h" |
23077 | 68 |
33555 | 69 void uiMainDraw( void ) |
23077 | 70 { |
71 | |
33768 | 72 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
|
73 |
33555 | 74 if ( guiApp.mainWindow.Visible == wsWindowNotVisible || |
23077 | 75 !mainVisible ) return; |
33555 | 76 // !guiApp.mainWindow.Mapped ) return; |
23077 | 77 |
33555 | 78 if ( uiMainRender && guiApp.mainWindow.State == wsWindowExpose ) |
23077 | 79 { |
33555 | 80 btnModify( evSetMoviePosition,guiInfo.Position ); |
81 btnModify( evSetVolume,guiInfo.Volume ); | |
23077 | 82 |
33555 | 83 fast_memcpy( mainDrawBuffer,guiApp.main.Bitmap.Image,guiApp.main.Bitmap.ImageSize ); |
84 RenderAll( &guiApp.mainWindow,guiApp.mainItems,guiApp.IndexOfMainItems,mainDrawBuffer ); | |
35493 | 85 uiMainRender=False; |
23077 | 86 } |
35746 | 87 // 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
|
88 wsImageDraw( &guiApp.mainWindow ); |
23077 | 89 // XFlush( wsDisplay ); |
90 } | |
91 | |
35762 | 92 void uiMainMouse( int Button,int X,int Y,int RX,int RY ) |
23077 | 93 { |
94 static int itemtype = 0; | |
95 int i; | |
35688 | 96 guiItem * item = NULL; |
23077 | 97 float value = 0.0f; |
98 | |
99 static int SelectedItem = -1; | |
100 int currentselected = -1; | |
101 | |
33555 | 102 for ( i=0;i <= guiApp.IndexOfMainItems;i++ ) |
103 if ( ( guiApp.mainItems[i].pressed != btnDisabled )&& | |
35675 | 104 ( 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 | 105 { currentselected=i; break; } |
106 | |
107 switch ( Button ) | |
108 { | |
109 case wsPMMouseButton: | |
34333 | 110 gtkShow( ivHidePopUpMenu,NULL ); |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35763
diff
changeset
|
111 uiMenuShow( RX,RY ); |
23077 | 112 itemtype=itPRMButton; |
113 break; | |
114 case wsRMMouseButton: | |
35766
16ed8155439b
Rename uiShowMenu() uiMenuShow() and uiHideMenu() uiMenuHide().
ib
parents:
35763
diff
changeset
|
115 uiMenuHide( RX,RY,0 ); |
23077 | 116 break; |
117 | |
118 case wsPLMouseButton: | |
34333 | 119 gtkShow( ivHidePopUpMenu,NULL ); |
35493 | 120 sx=X; sy=Y; boxMoved=True; itemtype=itPLMButton; |
23077 | 121 SelectedItem=currentselected; |
122 if ( SelectedItem == -1 ) break; | |
35493 | 123 boxMoved=False; |
33555 | 124 item=&guiApp.mainItems[SelectedItem]; |
23077 | 125 itemtype=item->type; |
126 item->pressed=btnPressed; | |
127 switch( item->type ) | |
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; | |
135 } | |
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: | |
32911 | 151 btnModify( item->message,(float)( X - item->x ) / item->width * 100.0f ); |
35768 | 152 uiMainEvent( item->message,item->value ); |
23077 | 153 value=item->value; |
154 break; | |
155 case itVPotmeter: | |
32911 | 156 btnModify( item->message, ( 1. - (float)( Y - item->y ) / item->height) * 100.0f ); |
35768 | 157 uiMainEvent( item->message,item->value ); |
23077 | 158 value=item->value; |
159 break; | |
160 } | |
35768 | 161 uiMainEvent( 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 ); | |
35768 | 180 uiMainEvent( 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: | |
35762 | 194 uiMenuMouse( RX,RY ); |
23077 | 195 break; |
196 case itPotmeter: | |
197 item->value=(float)( X - item->x ) / item->width * 100.0f; | |
198 goto potihandled; | |
199 case itVPotmeter: | |
200 item->value=(1. - (float)( Y - item->y ) / item->height) * 100.0f; | |
201 goto potihandled; | |
202 case itHPotmeter: | |
203 item->value=(float)( X - item->x ) / item->width * 100.0f; | |
204 potihandled: | |
205 if ( item->value > 100.0f ) item->value=100.0f; | |
206 if ( item->value < 0.0f ) item->value=0.0f; | |
35768 | 207 uiMainEvent( item->message,item->value ); |
23077 | 208 break; |
209 } | |
210 break; | |
211 } | |
212 } | |
213 | |
35762 | 214 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 { |
35768 | 251 uiMainEvent( evNormalSize,0 ); |
23077 | 252 return; |
253 } | |
254 default: vo_x11_putkey( Key ); return; | |
255 } | |
256 } | |
35768 | 257 if ( msg != evNone ) uiMainEvent( msg,0 ); |
23077 | 258 } |
259 | |
35759 | 260 /* this will be used to handle drag & drop files */ |
35763 | 261 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 ); | |
35768 | 332 if ( guiInfo.Playing == GUI_PLAY ) uiMainEvent( evStop,0 ); |
333 uiMainEvent( evPlay,0 ); | |
23077 | 334 } |
335 if (subtitles) { | |
33897 | 336 nfree(guiInfo.SubtitleFilename); |
337 guiInfo.SubtitleFilename = subtitles; | |
338 mplayerLoadSubtitle(guiInfo.SubtitleFilename); | |
23077 | 339 } |
340 } |