Commit 227de1f7 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Try to correctly guess which button has been clicked in the mozilla toolbar.

parent afe32c01
...@@ -672,4 +672,82 @@ void VlcPlugin::redrawToolbar() ...@@ -672,4 +672,82 @@ void VlcPlugin::redrawToolbar()
XFreeGC( p_display, gc ); XFreeGC( p_display, gc );
} }
vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
{
unsigned int i_dest = 0;
int i_playing = 0;
bool b_mute = false;
libvlc_exception_t ex;
if( i_xpos >= i_tb_height )
return clicked_Unknown;
/* Note: the order of testing is dependend on the original
* drawing positions of the icon buttons. Buttons are tested
* left to right.
*/
/* get isplaying */
libvlc_exception_init( &ex );
i_playing = libvlc_playlist_isplaying( getVLC(), &ex );
libvlc_exception_clear( &ex );
/* get mute info */
libvlc_exception_init(&ex);
b_mute = libvlc_audio_get_mute( getVLC(), &ex );
libvlc_exception_clear( &ex );
/* is Pause of Play button clicked */
if( (i_playing != 1) &&
(i_ypos >= BTN_SPACE>>1) &&
(i_ypos <= p_btnPlay->width + (BTN_SPACE>>1)) )
return clicked_Play;
else if( (i_ypos >= BTN_SPACE>>1) &&
(i_ypos <= p_btnPause->width) )
return clicked_Pause;
/* is Stop button clicked */
if( i_playing != 1 )
i_dest += BTN_SPACE + p_btnPause->width + (BTN_SPACE>>1);
else
i_dest += BTN_SPACE + p_btnPlay->width + (BTN_SPACE>>1);
if( (i_ypos >= i_dest) &&
(i_ypos <= p_btnStop->width + (BTN_SPACE>>1)) )
return clicked_Stop;
/* is Fullscreen button clicked */
i_dest += (p_btnStop->width + (BTN_SPACE>>1));
if( (i_ypos >= i_dest) &&
(i_ypos <= p_btnFullscreen->width + (BTN_SPACE>>1)) )
return clicked_Fullscreen;
/* is Mute or Unmute button clicked */
i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
if( !b_mute && (i_ypos >= i_dest) &&
(i_ypos <= p_btnMute->width + (BTN_SPACE>>1)) )
return clicked_Mute;
else if( (i_ypos >= i_dest) &&
(i_ypos <= p_btnUnmute->width + (BTN_SPACE>>1)) )
return clicked_Unmute;
/* is timeline clicked */
if( !b_mute )
i_dest += (p_btnMute->width + (BTN_SPACE>>1));
else
i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
if( (i_ypos >= i_dest) &&
(i_ypos <= p_timeline->width + (BTN_SPACE>>1)) )
return clicked_timeline;
/* is time button clicked */
i_dest += (p_timeline->width + (BTN_SPACE>>1));
if( (i_ypos >= i_dest) &&
(i_ypos <= p_btnTime->width + (BTN_SPACE>>1)) )
return clicked_Time;
return clicked_Unknown;
}
#undef BTN_SPACE
#endif #endif
...@@ -66,6 +66,18 @@ ...@@ -66,6 +66,18 @@
# define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) ) # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
#endif #endif
typedef enum vlc_toolbar_clicked_e {
clicked_Unknown = 0,
clicked_Play,
clicked_Pause,
clicked_Stop,
clicked_timeline,
clicked_Time,
clicked_Fullscreen,
clicked_Mute,
clicked_Unmute
} vlc_toolbar_clicked_t;
class VlcPlugin class VlcPlugin
{ {
public: public:
...@@ -115,6 +127,7 @@ public: ...@@ -115,6 +127,7 @@ public:
{ *width = i_tb_width; *height = i_tb_height; }; { *width = i_tb_width; *height = i_tb_height; };
int setToolbarSize(unsigned int width, unsigned int height) int setToolbarSize(unsigned int width, unsigned int height)
{ i_tb_width = width; i_tb_height = height; return 1; }; { i_tb_width = width; i_tb_height = height; return 1; };
vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
#endif #endif
uint16 i_npmode; /* either NP_EMBED or NP_FULL */ uint16 i_npmode; /* either NP_EMBED or NP_FULL */
......
...@@ -842,74 +842,90 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) ...@@ -842,74 +842,90 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex); libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
/* jump in the movie */ vlc_toolbar_clicked_t clicked;
if( i_yPos <= (i_height-30) ) clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos );
switch( clicked )
{ {
/* if a movie is loaded */ case clicked_Play:
if( p_md ) case clicked_Pause:
{ {
int64_t f_length; int i_playing;
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
f_length = libvlc_media_player_get_length( p_md, &ex ) / 100; i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
f_length = (float)f_length * libvlc_exception_init( &ex );
( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) ); if( i_playing == 1 )
libvlc_playlist_pause( p_plugin->getVLC(), &ex );
else
libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
libvlc_exception_clear( &ex );
}
break;
case clicked_Stop:
{
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
libvlc_media_player_set_time( p_md, f_length, &ex ); libvlc_playlist_stop( p_plugin->getVLC(), &ex );
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
} }
} break;
/* play/pause toggle */ case clicked_timeline:
if( (i_yPos > (i_height-30)) && (i_xPos > 4) && (i_xPos <= 39) ) {
{ /* if a movie is loaded */
int i_playing; if( p_md )
libvlc_exception_init( &ex ); {
i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex ); int64_t f_length;
libvlc_exception_clear( &ex ); libvlc_exception_init( &ex );
f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
libvlc_exception_clear( &ex );
libvlc_exception_init( &ex ); f_length = (float)f_length *
if( i_playing == 1 ) ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
libvlc_playlist_pause( p_plugin->getVLC(), &ex );
else
libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
libvlc_exception_clear( &ex );
}
/* stop */ libvlc_exception_init( &ex );
if( (i_yPos > (i_height-30)) && (i_xPos > 39) && (i_xPos < 67) ) libvlc_media_player_set_time( p_md, f_length, &ex );
{ libvlc_exception_clear( &ex );
libvlc_exception_init( &ex ); }
libvlc_playlist_stop( p_plugin->getVLC(), &ex ); }
libvlc_exception_clear( &ex ); break;
}
/* fullscreen */ case clicked_Time:
if( (i_yPos > (i_height-30)) && (i_xPos >= 67) && (i_xPos < 94) ) {
{ /* Not implemented yet*/
int i_playing; }
libvlc_exception_init( &ex ); break;
i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
libvlc_exception_clear( &ex );
if( (i_playing == 1) && p_md ) case clicked_Fullscreen:
{ {
int i_playing;
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
libvlc_set_fullscreen( p_md, 1, &ex ); i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
if( (i_playing == 1) && p_md )
{
libvlc_exception_init( &ex );
libvlc_set_fullscreen( p_md, 1, &ex );
libvlc_exception_clear( &ex );
}
} }
} break;
/* mute toggle */ case clicked_Mute:
if( (i_yPos > (i_height-30)) && (i_xPos >= 94) && (i_xPos < 109)) case clicked_Unmute:
{ {
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex ); libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
libvlc_exception_clear( &ex ); libvlc_exception_clear( &ex );
} }
break;
default: /* button_Unknown */
break;
}
if( p_md ) libvlc_media_player_release( p_md ); if( p_md ) libvlc_media_player_release( p_md );
} }
Redraw( w, closure, event ); Redraw( w, closure, event );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment