Remove trailing whitespace from most files
[mplayer/glamo.git] / gui / mplayer / pb.c
blob9238755d91f5840f810076cbf212680feb49df37
1 /*
2 * main window
4 * This file is part of MPlayer.
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.
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.
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.
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <inttypes.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <string.h>
28 #include "config.h"
29 #include "gui/app.h"
30 #include "gui/skin/font.h"
31 #include "gui/skin/skin.h"
32 #include "gui/wm/ws.h"
34 #include "help_mp.h"
35 #include "libvo/x11_common.h"
36 #include "libvo/fastmemcpy.h"
38 #include "stream/stream.h"
39 #include "mixer.h"
40 #include "libvo/sub.h"
42 #include "libmpdemux/demuxer.h"
43 #include "libmpdemux/stheader.h"
44 #include "codec-cfg.h"
46 #include "gmplayer.h"
47 #include "play.h"
48 #include "widgets.h"
49 #include "gui_common.h"
51 unsigned int GetTimerMS( void );
52 unsigned int GetTimer( void );
54 unsigned char * mplPBDrawBuffer = NULL;
55 int mplPBVisible = 0;
56 int mplPBLength = 0;
57 int mplPBFade = 0;
59 void mplPBDraw( void )
61 int x;
63 if ( !appMPlayer.subWindow.isFullScreen ) return;
64 if ( !mplPBVisible || !appMPlayer.barIsPresent ) return;
66 // appMPlayer.bar.x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ) / 2;
67 switch( appMPlayer.bar.x )
69 case -1: x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ) / 2; break;
70 case -2: x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ); break;
71 default: x=appMPlayer.bar.x;
74 switch ( mplPBFade )
76 case 1: // fade in
77 mplPBLength--;
78 if ( appMPlayer.subWindow.Height - appMPlayer.bar.height >= mplPBLength )
80 mplPBLength=appMPlayer.subWindow.Height - appMPlayer.bar.height;
81 mplPBFade=0;
82 vo_mouse_autohide=0;
84 wsMoveWindow( &appMPlayer.barWindow,0,x,mplPBLength );
85 break;
86 case 2: // fade out
87 mplPBLength+=10;
88 if ( mplPBLength > appMPlayer.subWindow.Height )
90 mplPBLength=appMPlayer.subWindow.Height;
91 mplPBFade=mplPBVisible=0;
92 vo_mouse_autohide=1;
93 wsVisibleWindow( &appMPlayer.barWindow,wsHideWindow );
94 return;
96 wsMoveWindow( &appMPlayer.barWindow,0,x,mplPBLength );
97 break;
100 // --- render
101 if ( appMPlayer.barWindow.State == wsWindowExpose )
103 btnModify( evSetMoviePosition,guiIntfStruct.Position );
104 btnModify( evSetVolume,guiIntfStruct.Volume );
106 vo_mouse_autohide=0;
108 fast_memcpy( mplPBDrawBuffer,appMPlayer.bar.Bitmap.Image,appMPlayer.bar.Bitmap.ImageSize );
109 Render( &appMPlayer.barWindow,appMPlayer.barItems,appMPlayer.NumberOfBarItems,mplPBDrawBuffer,appMPlayer.bar.Bitmap.ImageSize );
110 wsConvert( &appMPlayer.barWindow,mplPBDrawBuffer,appMPlayer.bar.Bitmap.ImageSize );
112 wsPutImage( &appMPlayer.barWindow );
115 #define itPLMButton (itNULL - 1)
116 #define itPRMButton (itNULL - 2)
118 void mplPBMouseHandle( int Button,int X,int Y,int RX,int RY )
120 static int itemtype = 0;
121 int i;
122 wItem * item = NULL;
123 float value = 0.0f;
125 static int SelectedItem = -1;
126 int currentselected = -1;
128 for ( i=0;i < appMPlayer.NumberOfBarItems + 1;i++ )
129 if ( ( appMPlayer.barItems[i].pressed != btnDisabled )&&
130 ( wgIsRect( X,Y,appMPlayer.barItems[i].x,appMPlayer.barItems[i].y,appMPlayer.barItems[i].x+appMPlayer.barItems[i].width,appMPlayer.barItems[i].y+appMPlayer.barItems[i].height ) ) )
131 { currentselected=i; break; }
133 switch ( Button )
135 case wsPMMouseButton:
136 gtkShow( evHidePopUpMenu,NULL );
137 mplShowMenu( RX,RY );
138 break;
139 case wsRMMouseButton:
140 mplHideMenu( RX,RY,0 );
141 break;
142 case wsRRMouseButton:
143 gtkShow( evShowPopUpMenu,NULL );
144 break;
145 // ---
146 case wsPLMouseButton:
147 gtkShow( evHidePopUpMenu,NULL );
148 SelectedItem=currentselected;
149 if ( SelectedItem == -1 ) break; // yeees, i'm move the fucking window
150 item=&appMPlayer.barItems[SelectedItem];
151 itemtype=item->type;
152 item->pressed=btnPressed;
154 switch( item->type )
156 case itButton:
157 if ( ( SelectedItem > -1 ) &&
158 ( ( ( item->msg == evPlaySwitchToPause && item->msg == evPauseSwitchToPlay ) ) ||
159 ( ( item->msg == evPauseSwitchToPlay && item->msg == evPlaySwitchToPause ) ) ) )
160 { item->pressed=btnDisabled; }
161 break;
164 break;
165 case wsRLMouseButton:
166 item=&appMPlayer.barItems[SelectedItem];
167 item->pressed=btnReleased;
168 SelectedItem=-1;
169 if ( currentselected == - 1 ) { itemtype=0; break; }
170 value=0;
172 switch( itemtype )
174 case itPotmeter:
175 case itHPotmeter:
176 btnModify( item->msg,(float)( X - item->x ) / item->width * 100.0f );
177 mplEventHandling( item->msg,item->value );
178 value=item->value;
179 break;
180 case itVPotmeter:
181 btnModify( item->msg, ( 1. - (float)( Y - item->y ) / item->height) * 100.0f );
182 mplEventHandling( item->msg,item->value );
183 value=item->value;
184 break;
186 mplEventHandling( item->msg,value );
188 itemtype=0;
189 break;
190 // ---
191 case wsP5MouseButton: value=-2.5f; goto rollerhandled;
192 case wsP4MouseButton: value= 2.5f;
193 rollerhandled:
194 item=&appMPlayer.barItems[currentselected];
195 if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itPotmeter ) )
197 item->value+=value;
198 btnModify( item->msg,item->value );
199 mplEventHandling( item->msg,item->value );
201 break;
202 // ---
203 case wsMoveMouse:
204 item=&appMPlayer.barItems[SelectedItem];
205 switch ( itemtype )
207 case itPRMButton:
208 mplMenuMouseHandle( X,Y,RX,RY );
209 break;
210 case itPotmeter:
211 item->value=(float)( X - item->x ) / item->width * 100.0f;
212 goto potihandled;
213 case itVPotmeter:
214 item->value=(1. - (float)( Y - item->y ) / item->height) * 100.0f;
215 goto potihandled;
216 case itHPotmeter:
217 item->value=(float)( X - item->x ) / item->width * 100.0f;
218 potihandled:
219 if ( item->value > 100.0f ) item->value=100.0f;
220 if ( item->value < 0.0f ) item->value=0.0f;
221 mplEventHandling( item->msg,item->value );
222 break;
224 break;
228 void mplPBShow( int x, int y )
230 if ( !appMPlayer.barIsPresent || !gtkEnablePlayBar ) return;
231 if ( !appMPlayer.subWindow.isFullScreen ) return;
233 if ( y > appMPlayer.subWindow.Height - appMPlayer.bar.height )
235 if ( !mplPBFade ) wsVisibleWindow( &appMPlayer.barWindow,wsShowWindow );
236 mplPBFade=1; mplPBVisible=1; wsPostRedisplay( &appMPlayer.barWindow );
238 else if ( !mplPBFade ) mplPBFade=2;
241 void mplPBInit( void )
243 if ( !appMPlayer.barIsPresent ) return;
245 gfree( (void**)&mplPBDrawBuffer );
247 if ( ( mplPBDrawBuffer = malloc( appMPlayer.bar.Bitmap.ImageSize ) ) == NULL )
249 mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_NEMDB );
250 exit( 0 );
253 appMPlayer.barWindow.Parent=appMPlayer.subWindow.WindowID;
254 wsCreateWindow( &appMPlayer.barWindow,
255 appMPlayer.bar.x,appMPlayer.bar.y,appMPlayer.bar.width,appMPlayer.bar.height,
256 wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsHideFrame|wsHideWindow,"PlayBar" );
258 wsSetShape( &appMPlayer.barWindow,appMPlayer.bar.Mask.Image );
260 appMPlayer.barWindow.ReDraw=(void *)mplPBDraw;
261 appMPlayer.barWindow.MouseHandler=mplPBMouseHandle;
262 appMPlayer.barWindow.KeyHandler=mplMainKeyHandle;
264 mplPBLength=appMPlayer.subWindow.Height;