Mercurial > mplayer.hg
annotate gui/ui/playbar.c @ 34615:306ee51a2fa0
Deduplicate some code that exists both in the if and else branch.
author | reimar |
---|---|
date | Sun, 12 Feb 2012 19:27:35 +0000 |
parents | f866092d51cd |
children | b03481253518 |
rev | line source |
---|---|
26458 | 1 /* |
2 * main window | |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
23077 | 20 |
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:
23077
diff
changeset
|
25 #include <string.h> |
23077 | 26 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
27 #include "config.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
28 #include "gui/app.h" |
33738 | 29 #include "gui/interface.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
30 #include "gui/skin/font.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
31 #include "gui/skin/skin.h" |
33739 | 32 #include "gui/util/mem.h" |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
33 #include "gui/wm/ws.h" |
23077 | 34 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
35 #include "help_mp.h" |
33024 | 36 #include "mp_core.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
37 #include "libvo/x11_common.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
38 #include "libvo/fastmemcpy.h" |
23077 | 39 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
40 #include "stream/stream.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
41 #include "mixer.h" |
32467 | 42 #include "sub/sub.h" |
23077 | 43 |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
44 #include "libmpdemux/demuxer.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
45 #include "libmpdemux/stheader.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
46 #include "codec-cfg.h" |
23077 | 47 |
48 #include "gmplayer.h" | |
33556 | 49 #include "actions.h" |
23077 | 50 #include "widgets.h" |
33556 | 51 #include "render.h" |
23077 | 52 |
28051 | 53 unsigned int GetTimerMS( void ); |
54 unsigned int GetTimer( void ); | |
23077 | 55 |
33555 | 56 unsigned char * playbarDrawBuffer = NULL; |
57 int playbarVisible = 0; | |
58 int playbarLength = 0; | |
59 int uiPlaybarFade = 0; | |
23077 | 60 |
33555 | 61 static void uiPlaybarDraw( void ) |
23077 | 62 { |
63 int x; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
64 |
33555 | 65 if ( !guiApp.subWindow.isFullScreen ) return; |
66 if ( !playbarVisible || !guiApp.playbarIsPresent ) return; | |
23077 | 67 |
33555 | 68 // guiApp.playbar.x=( guiApp.subWindow.Width - guiApp.playbar.width ) / 2; |
69 switch( guiApp.playbar.x ) | |
23077 | 70 { |
33555 | 71 case -1: x=( guiApp.subWindow.Width - guiApp.playbar.width ) / 2; break; |
72 case -2: x=( guiApp.subWindow.Width - guiApp.playbar.width ); break; | |
73 default: x=guiApp.playbar.x; | |
23077 | 74 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
75 |
33555 | 76 switch ( uiPlaybarFade ) |
23077 | 77 { |
78 case 1: // fade in | |
33555 | 79 playbarLength--; |
80 if ( guiApp.subWindow.Height - guiApp.playbar.height >= playbarLength ) | |
23077 | 81 { |
33555 | 82 playbarLength=guiApp.subWindow.Height - guiApp.playbar.height; |
83 uiPlaybarFade=0; | |
23077 | 84 vo_mouse_autohide=0; |
85 } | |
33993 | 86 wsMoveWindow( &guiApp.playbarWindow,True,x,playbarLength ); |
23077 | 87 break; |
88 case 2: // fade out | |
33555 | 89 playbarLength+=10; |
90 if ( playbarLength > guiApp.subWindow.Height ) | |
23077 | 91 { |
33555 | 92 playbarLength=guiApp.subWindow.Height; |
93 uiPlaybarFade=playbarVisible=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
94 vo_mouse_autohide=1; |
33555 | 95 wsVisibleWindow( &guiApp.playbarWindow,wsHideWindow ); |
23077 | 96 return; |
97 } | |
33993 | 98 wsMoveWindow( &guiApp.playbarWindow,True,x,playbarLength ); |
23077 | 99 break; |
100 } | |
101 | |
102 // --- render | |
33555 | 103 if ( guiApp.playbarWindow.State == wsWindowExpose ) |
23077 | 104 { |
33555 | 105 btnModify( evSetMoviePosition,guiInfo.Position ); |
106 btnModify( evSetVolume,guiInfo.Volume ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
107 |
23077 | 108 vo_mouse_autohide=0; |
109 | |
33555 | 110 fast_memcpy( playbarDrawBuffer,guiApp.playbar.Bitmap.Image,guiApp.playbar.Bitmap.ImageSize ); |
111 RenderAll( &guiApp.playbarWindow,guiApp.playbarItems,guiApp.IndexOfPlaybarItems,playbarDrawBuffer ); | |
112 wsConvert( &guiApp.playbarWindow,playbarDrawBuffer ); | |
23077 | 113 } |
33555 | 114 wsPutImage( &guiApp.playbarWindow ); |
23077 | 115 } |
116 | |
33555 | 117 static void uiPlaybarMouseHandle( int Button, int X, int Y, int RX, int RY ) |
23077 | 118 { |
119 static int itemtype = 0; | |
120 int i; | |
121 wItem * item = NULL; | |
122 float value = 0.0f; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
123 |
23077 | 124 static int SelectedItem = -1; |
125 int currentselected = -1; | |
126 | |
33555 | 127 for ( i=0;i <= guiApp.IndexOfPlaybarItems;i++ ) |
128 if ( ( guiApp.playbarItems[i].pressed != btnDisabled )&& | |
129 ( wgIsRect( X,Y,guiApp.playbarItems[i].x,guiApp.playbarItems[i].y,guiApp.playbarItems[i].x+guiApp.playbarItems[i].width,guiApp.playbarItems[i].y+guiApp.playbarItems[i].height ) ) ) | |
23077 | 130 { currentselected=i; break; } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
131 |
23077 | 132 switch ( Button ) |
133 { | |
134 case wsPMMouseButton: | |
34333 | 135 gtkShow( ivHidePopUpMenu,NULL ); |
33555 | 136 uiShowMenu( RX,RY ); |
23077 | 137 break; |
138 case wsRMMouseButton: | |
33555 | 139 uiHideMenu( RX,RY,0 ); |
23077 | 140 break; |
141 case wsRRMouseButton: | |
34333 | 142 gtkShow( ivShowPopUpMenu,NULL ); |
23077 | 143 break; |
144 // --- | |
145 case wsPLMouseButton: | |
34333 | 146 gtkShow( ivHidePopUpMenu,NULL ); |
23077 | 147 SelectedItem=currentselected; |
148 if ( SelectedItem == -1 ) break; // yeees, i'm move the fucking window | |
33555 | 149 item=&guiApp.playbarItems[SelectedItem]; |
23077 | 150 itemtype=item->type; |
151 item->pressed=btnPressed; | |
152 | |
153 switch( item->type ) | |
154 { | |
155 case itButton: | |
156 if ( ( SelectedItem > -1 ) && | |
32911 | 157 ( ( ( item->message == evPlaySwitchToPause && item->message == evPauseSwitchToPlay ) ) || |
158 ( ( item->message == evPauseSwitchToPlay && item->message == evPlaySwitchToPause ) ) ) ) | |
23077 | 159 { item->pressed=btnDisabled; } |
160 break; | |
161 } | |
162 | |
163 break; | |
164 case wsRLMouseButton: | |
33107 | 165 if ( SelectedItem != -1 ) // NOTE TO MYSELF: only if itButton, itHPotmeter or itVPotmeter |
166 { | |
33555 | 167 item=&guiApp.playbarItems[SelectedItem]; |
33108 | 168 item->pressed=btnReleased; |
33107 | 169 } |
23077 | 170 SelectedItem=-1; |
171 if ( currentselected == - 1 ) { itemtype=0; break; } | |
172 value=0; | |
173 | |
174 switch( itemtype ) | |
175 { | |
176 case itPotmeter: | |
177 case itHPotmeter: | |
32911 | 178 btnModify( item->message,(float)( X - item->x ) / item->width * 100.0f ); |
33555 | 179 uiEventHandling( item->message,item->value ); |
23077 | 180 value=item->value; |
181 break; | |
182 case itVPotmeter: | |
32911 | 183 btnModify( item->message, ( 1. - (float)( Y - item->y ) / item->height) * 100.0f ); |
33555 | 184 uiEventHandling( item->message,item->value ); |
23077 | 185 value=item->value; |
186 break; | |
187 } | |
33555 | 188 uiEventHandling( item->message,value ); |
23077 | 189 |
190 itemtype=0; | |
191 break; | |
192 // --- | |
193 case wsP5MouseButton: value=-2.5f; goto rollerhandled; | |
194 case wsP4MouseButton: value= 2.5f; | |
195 rollerhandled: | |
33555 | 196 item=&guiApp.playbarItems[currentselected]; |
23077 | 197 if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itPotmeter ) ) |
198 { | |
199 item->value+=value; | |
32911 | 200 btnModify( item->message,item->value ); |
33555 | 201 uiEventHandling( item->message,item->value ); |
23077 | 202 } |
203 break; | |
204 // --- | |
205 case wsMoveMouse: | |
33555 | 206 item=&guiApp.playbarItems[SelectedItem]; |
23077 | 207 switch ( itemtype ) |
208 { | |
209 case itPRMButton: | |
34472 | 210 uiMenuMouseHandle( RX,RY ); |
23077 | 211 break; |
212 case itPotmeter: | |
213 item->value=(float)( X - item->x ) / item->width * 100.0f; | |
214 goto potihandled; | |
215 case itVPotmeter: | |
216 item->value=(1. - (float)( Y - item->y ) / item->height) * 100.0f; | |
217 goto potihandled; | |
218 case itHPotmeter: | |
219 item->value=(float)( X - item->x ) / item->width * 100.0f; | |
220 potihandled: | |
221 if ( item->value > 100.0f ) item->value=100.0f; | |
222 if ( item->value < 0.0f ) item->value=0.0f; | |
33555 | 223 uiEventHandling( item->message,item->value ); |
23077 | 224 break; |
225 } | |
226 break; | |
227 } | |
228 } | |
229 | |
34471 | 230 void uiPlaybarShow( int y ) |
23077 | 231 { |
33555 | 232 if ( !guiApp.playbarIsPresent || !gtkEnablePlayBar ) return; |
233 if ( !guiApp.subWindow.isFullScreen ) return; | |
23077 | 234 |
33555 | 235 if ( y > guiApp.subWindow.Height - guiApp.playbar.height ) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
236 { |
33555 | 237 if ( !uiPlaybarFade ) wsVisibleWindow( &guiApp.playbarWindow,wsShowWindow ); |
238 uiPlaybarFade=1; playbarVisible=1; wsPostRedisplay( &guiApp.playbarWindow ); | |
23077 | 239 } |
33555 | 240 else if ( !uiPlaybarFade ) uiPlaybarFade=2; |
23077 | 241 } |
242 | |
33555 | 243 void uiPlaybarInit( void ) |
23077 | 244 { |
33555 | 245 if ( !guiApp.playbarIsPresent ) return; |
23077 | 246 |
33739 | 247 nfree( playbarDrawBuffer ); |
23077 | 248 |
33555 | 249 if ( ( playbarDrawBuffer = malloc( guiApp.playbar.Bitmap.ImageSize ) ) == NULL ) |
23077 | 250 { |
33024 | 251 gmp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_NEMDB ); |
33768 | 252 mplayer( MPLAYER_EXIT_GUI, EXIT_ERROR, 0 ); |
23077 | 253 } |
254 | |
33555 | 255 guiApp.playbarWindow.Parent=guiApp.subWindow.WindowID; |
256 wsCreateWindow( &guiApp.playbarWindow, | |
257 guiApp.playbar.x,guiApp.playbar.y,guiApp.playbar.width,guiApp.playbar.height, | |
23077 | 258 wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsHideFrame|wsHideWindow,"PlayBar" ); |
259 | |
33555 | 260 wsSetShape( &guiApp.playbarWindow,guiApp.playbar.Mask.Image ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
261 |
33555 | 262 guiApp.playbarWindow.ReDraw=(void *)uiPlaybarDraw; |
263 guiApp.playbarWindow.MouseHandler=uiPlaybarMouseHandle; | |
264 guiApp.playbarWindow.KeyHandler=uiMainKeyHandle; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28051
diff
changeset
|
265 |
33555 | 266 playbarLength=guiApp.subWindow.Height; |
23077 | 267 } |