aboutsummaryrefslogtreecommitdiffhomepage
path: root/Gui/mplayer/pb.c
blob: 644729e660c7112af589a15fc25f303576c5fc26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240

// main window

#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <unistd.h>

#include "../app.h"
#include "../skin/font.h"
#include "../skin/skin.h"
#include "../wm/ws.h"

#include "../../config.h"
#include "../../help_mp.h"
#include "../../libvo/x11_common.h"
#include "../../libvo/fastmemcpy.h"

#include "../../libmpdemux/stream.h"
#include "../../mixer.h"
#include "../../libvo/sub.h"
#include "../../mplayer.h"

#include "../../libmpdemux/demuxer.h"
#include "../../libmpdemux/stheader.h"
#include "../../codec-cfg.h"

#include "play.h"
#include "widgets.h"
#include "common.h"

extern unsigned int GetTimerMS( void );
extern unsigned int GetTimer( void );

unsigned char * mplPBDrawBuffer = NULL;
int		mplPBVisible = 0;
int  		mplPBLength = 0;
int		mplPBFade = 0;

void mplPBDraw( void )
{
 int x;
 
 if ( !appMPlayer.subWindow.isFullScreen ) return;
 if ( !mplPBVisible || !appMPlayer.barIsPresent ) return;

// appMPlayer.bar.x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ) / 2;
 switch( appMPlayer.bar.x )
  {
   case -1: x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ) / 2; break;
   case -2: x=( appMPlayer.subWindow.Width - appMPlayer.bar.width ); break;
   default: x=appMPlayer.bar.x;
  }
	      
 switch ( mplPBFade )
  {
   case 1: // fade in
        mplPBLength--;
        if ( appMPlayer.subWindow.Height - appMPlayer.bar.height >= mplPBLength )
	 {
	  mplPBLength=appMPlayer.subWindow.Height - appMPlayer.bar.height;
	  mplPBFade=0;
	  vo_mouse_autohide=0;
	 }
        wsMoveWindow( &appMPlayer.barWindow,0,x,mplPBLength ); 
	break;
   case 2: // fade out
	mplPBLength+=10;
	if ( mplPBLength > appMPlayer.subWindow.Height )
	 {
	  mplPBLength=appMPlayer.subWindow.Height;
	  mplPBFade=mplPBVisible=0;
          vo_mouse_autohide=1; 
          wsVisibleWindow( &appMPlayer.barWindow,wsHideWindow ); 
	  return;
	 }
        wsMoveWindow( &appMPlayer.barWindow,0,x,mplPBLength ); 
	break;
  }

// --- render
 if ( appMPlayer.barWindow.State == wsWindowExpose )
  {
   btnModify( evSetMoviePosition,guiIntfStruct.Position );
   btnModify( evSetVolume,guiIntfStruct.Volume );
   
   vo_mouse_autohide=0;

   memcpy( mplPBDrawBuffer,appMPlayer.bar.Bitmap.Image,appMPlayer.bar.Bitmap.ImageSize );
   Render( &appMPlayer.barWindow,appMPlayer.barItems,appMPlayer.NumberOfBarItems,mplPBDrawBuffer,appMPlayer.bar.Bitmap.ImageSize );
   wsConvert( &appMPlayer.barWindow,mplPBDrawBuffer,appMPlayer.bar.Bitmap.ImageSize );   
  }
 wsPutImage( &appMPlayer.barWindow );
}

#define itPLMButton (itNULL - 1)
#define itPRMButton (itNULL - 2)

void mplPBMouseHandle( int Button,int X,int Y,int RX,int RY )
{
 static int     itemtype = 0;
        int     i;
        wItem * item = NULL;
	float   value = 0.0f;
			 
 static int     SelectedItem = -1;
	int     currentselected = -1;

 for ( i=0;i < appMPlayer.NumberOfBarItems + 1;i++ )
   if ( ( appMPlayer.barItems[i].pressed != btnDisabled )&&
      ( 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 ) ) )
    { currentselected=i; break; }
		    
 switch ( Button )
  {
   case wsPMMouseButton:
        gtkShow( evHidePopUpMenu,NULL );
        mplShowMenu( RX,RY );
        break;
   case wsRMMouseButton:
        mplHideMenu( RX,RY,0 );
        break;
   case wsPRMouseButton:
        gtkShow( evShowPopUpMenu,NULL );
	break;
// ---
   case wsPLMouseButton:
	gtkShow( evHidePopUpMenu,NULL );
        SelectedItem=currentselected;
        if ( SelectedItem == -1 ) break; // yeees, i'm move the fucking window
        item=&appMPlayer.barItems[SelectedItem];
	itemtype=item->type;
	item->pressed=btnPressed;

	switch( item->type )
	 {
	  case itButton:
	       if ( ( SelectedItem > -1 ) &&
	         ( ( ( item->msg == evPlaySwitchToPause && item->msg == evPauseSwitchToPlay ) ) ||
		 ( ( item->msg == evPauseSwitchToPlay && item->msg == evPlaySwitchToPause ) ) ) )
		 { item->pressed=btnDisabled; }
	       break;
	 }

	break;
   case wsRLMouseButton:
	item=&appMPlayer.barItems[SelectedItem];
	item->pressed=btnReleased;
	SelectedItem=-1;
	if ( currentselected == - 1 ) { itemtype=0; break; }
	value=0;

	switch( itemtype )
	 {
	  case itPotmeter:
	  case itVPotmeter:
	  case itHPotmeter:
	       btnModify( item->msg,(float)( X - item->x ) / item->width * 100.0f );
	       mplEventHandling( item->msg,item->value );
	       value=item->value;
	       break;
	 }
	mplEventHandling( item->msg,value );

	itemtype=0;
	break;
// ---
   case wsP5MouseButton: value=-2.5f; goto rollerhandled;
   case wsP4MouseButton: value= 2.5f;
rollerhandled:
        item=&appMPlayer.barItems[currentselected];
        if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itPotmeter ) )
	 {
	  item->value+=value;
	  btnModify( item->msg,item->value );
	  mplEventHandling( item->msg,item->value );
	 }
	break;
// ---
   case wsMoveMouse:
        item=&appMPlayer.barItems[SelectedItem];
	switch ( itemtype )
	 {
	  case itPRMButton:
	       mplMenuMouseHandle( X,Y,RX,RY );
	       break;
	  case itPotmeter:
	       item->value=(float)( X - item->x ) / item->width * 100.0f;
	       goto potihandled;
	  case itHPotmeter:
	       item->value=(float)( X - item->x ) / item->width * 100.0f;
potihandled:
	       if ( item->value > 100.0f ) item->value=100.0f;
	       if ( item->value < 0.0f ) item->value=0.0f;
	       mplEventHandling( item->msg,item->value );
	       break;
	 }
        break;
  }
}

void mplPBShow( int x, int y )
{
 if ( !appMPlayer.barIsPresent || !gtkEnablePlayBar ) return;
 if ( !appMPlayer.subWindow.isFullScreen ) return;

 if ( y > appMPlayer.subWindow.Height - appMPlayer.bar.height ) 
  { 
   if ( !mplPBFade ) wsVisibleWindow( &appMPlayer.barWindow,wsShowWindow );
   mplPBFade=1; mplPBVisible=1; wsPostRedisplay( &appMPlayer.barWindow );
  }
  else if ( !mplPBFade ) mplPBFade=2;
}

void mplPBInit( void )
{
 if ( !appMPlayer.barIsPresent ) return;

 gfree( (void**)&mplPBDrawBuffer );

 if ( ( mplPBDrawBuffer = (unsigned char *)malloc( appMPlayer.bar.Bitmap.ImageSize ) ) == NULL )
  {
   mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_NEMDB );
   exit( 0 );
  }

 appMPlayer.barWindow.Parent=appMPlayer.subWindow.WindowID;
 wsCreateWindow( &appMPlayer.barWindow,
   appMPlayer.bar.x,appMPlayer.bar.y,appMPlayer.bar.width,appMPlayer.bar.height,
   wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsHideFrame|wsHideWindow,"PlayBar" );

 wsSetShape( &appMPlayer.barWindow,appMPlayer.bar.Mask.Image );
 
 appMPlayer.barWindow.ReDraw=(void *)mplPBDraw;
 appMPlayer.barWindow.MouseHandler=mplPBMouseHandle;
 appMPlayer.barWindow.KeyHandler=mplMainKeyHandle;
 
 mplPBLength=appMPlayer.subWindow.Height;
}