Commit 35979e86 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Refactor mozilla toolbar code. There are still a few things wrong:

- nice images
- fix playlist status bug
- timeslider not updated bug
- button/slider position and detection of button click is hardcoded
parent cd2efd35
...@@ -57,6 +57,7 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) : ...@@ -57,6 +57,7 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
#if XP_UNIX #if XP_UNIX
,i_width((unsigned)-1) ,i_width((unsigned)-1)
,i_height((unsigned)-1) ,i_height((unsigned)-1)
,i_last_position(0)
#endif #endif
{ {
memset(&npwindow, 0, sizeof(NPWindow)); memset(&npwindow, 0, sizeof(NPWindow));
...@@ -443,5 +444,169 @@ int VlcPlugin::setSize(unsigned width, unsigned height) ...@@ -443,5 +444,169 @@ int VlcPlugin::setSize(unsigned width, unsigned height)
/* return size */ /* return size */
return diff; return diff;
} }
#endif
void VlcPlugin::showToolbar()
{
const NPWindow& window = getWindow();
Window control = getControlWindow();
Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
/* load icons */
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
&p_btnPlay, NULL, NULL);
if( p_btnPlay )
i_control_height = __MAX( i_control_height, p_btnPlay->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
&p_btnPause, NULL, NULL);
if( p_btnPause )
i_control_height = __MAX( i_control_height, p_btnPause->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
&p_btnStop, NULL, NULL );
if( p_btnStop )
i_control_height = __MAX( i_control_height, p_btnStop->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
&p_timeline, NULL, NULL);
if( p_timeline )
i_control_height = __MAX( i_control_height, p_timeline->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
&p_btnTime, NULL, NULL);
if( p_btnTime )
i_control_height = __MAX( i_control_height, p_btnTime->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
&p_btnFullscreen, NULL, NULL);
if( p_btnFullscreen )
i_control_height = __MAX( i_control_height, p_btnFullscreen->height);
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
&p_btnMute, NULL, NULL);
if( p_btnMute )
i_control_height = __MAX( i_control_height, p_btnMute->height);
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
&p_btnUnmute, NULL, NULL);
if( p_btnUnmute )
i_control_height = __MAX( i_control_height, p_btnUnmute->height);
if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
!p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
}
void VlcPlugin::hideToolbar()
{
if( p_btnPlay ) XDestroyImage( p_btnPlay );
if( p_btnPause ) XDestroyImage( p_btnPause );
if( p_btnStop ) XDestroyImage( p_btnStop );
if( p_timeline ) XDestroyImage( p_timeline );
if( p_btnTime ) XDestroyImage( p_btnTime );
if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
if( p_btnMute ) XDestroyImage( p_btnMute );
if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
p_btnPlay = NULL;
p_btnPause = NULL;
p_btnStop = NULL;
p_timeline = NULL;
p_btnTime = NULL;
p_btnFullscreen = NULL;
p_btnMute = NULL;
p_btnUnmute = NULL;
}
void VlcPlugin::redrawToolbar()
{
libvlc_media_instance_t *p_md = NULL;
libvlc_exception_t ex;
float f_position = 0.0;
int i_playing = 0;
bool b_mute = false;
GC gc;
XGCValues gcv;
const NPWindow& window = getWindow();
Window control = getControlWindow();
Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
/* get media instance */
libvlc_exception_init( &ex );
p_md = libvlc_playlist_get_media_instance( getVLC(), &ex );
libvlc_exception_clear( &ex );
/* 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 );
/* get movie position in % */
if( i_playing == 1 )
{
libvlc_exception_init( &ex );
f_position = libvlc_media_instance_get_position( p_md, &ex ) * 100;
libvlc_exception_clear( &ex );
}
libvlc_media_instance_release( p_md );
gcv.foreground = BlackPixel( p_display, 0 );
gc = XCreateGC( p_display, control, GCForeground, &gcv );
XFillRectangle( p_display, control, gc,
0, 0, window.width, i_control_height );
gcv.foreground = WhitePixel( p_display, 0 );
XChangeGC( p_display, gc, GCForeground, &gcv );
/* position icons */
fprintf( stderr, ">>>>>> is playing = %d\n", i_playing );
if( p_btnPause && (i_playing == 1) )
{
XPutImage( p_display, control, gc, p_btnPause, 0, 0, 4, 14,
p_btnPause->width, p_btnPause->height );
}
else if( p_btnPlay )
{
XPutImage( p_display, control, gc, p_btnPlay, 0, 0, 4, 14,
p_btnPlay->width, p_btnPlay->height );
}
if( p_btnStop )
XPutImage( p_display, control, gc, p_btnStop, 0, 0, 39, 14,
p_btnStop->width, p_btnStop->height );
if( p_btnFullscreen )
XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, 67, 21,
p_btnFullscreen->width, p_btnFullscreen->height );
if( p_btnUnmute && b_mute )
{
XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, 94, 30,
p_btnUnmute->width, p_btnUnmute->height );
}
else if( p_btnMute )
{
XPutImage( p_display, control, gc, p_btnMute, 0, 0, 94, 30,
p_btnMute->width, p_btnMute->height );
}
if( p_timeline )
XPutImage( p_display, control, gc, p_timeline, 0, 0, 4, 4,
(window.width-8), p_timeline->height );
if( f_position > 0 )
i_last_position = (((float)window.width-8.0)/100.0)*f_position;
if( p_btnTime )
XPutImage( p_display, control, gc, p_btnTime,
0, 0, (4+i_last_position), 2,
p_btnTime->width, p_btnTime->height );
XFreeGC( p_display, gc );
}
#endif
...@@ -53,6 +53,17 @@ ...@@ -53,6 +53,17 @@
# include <X11/Intrinsic.h> # include <X11/Intrinsic.h>
# include <X11/StringDefs.h> # include <X11/StringDefs.h>
# include <X11/X.h> # include <X11/X.h>
# ifndef __APPLE__
# include <X11/xpm.h>
# endif
#endif
#ifndef __MAX
# define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
#endif
#ifndef __MIN
# define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
#endif #endif
class VlcPlugin class VlcPlugin
...@@ -96,6 +107,10 @@ public: ...@@ -96,6 +107,10 @@ public:
{ return npcontrol; }; { return npcontrol; };
void setControlWindow(Window window) void setControlWindow(Window window)
{ npcontrol = window; }; { npcontrol = window; };
void showToolbar();
void hideToolbar();
void redrawToolbar();
#endif #endif
uint16 i_npmode; /* either NP_EMBED or NP_FULL */ uint16 i_npmode; /* either NP_EMBED or NP_FULL */
...@@ -128,6 +143,16 @@ private: ...@@ -128,6 +143,16 @@ private:
unsigned int i_width, i_height; unsigned int i_width, i_height;
Window npvideo, npcontrol; Window npvideo, npcontrol;
XImage *p_btnPlay;
XImage *p_btnPause;
XImage *p_btnStop;
XImage *p_timeline;
XImage *p_btnTime;
XImage *p_btnFullscreen;
XImage *p_btnMute;
XImage *p_btnUnmute;
int i_last_position;
#endif #endif
}; };
......
...@@ -35,12 +35,6 @@ ...@@ -35,12 +35,6 @@
# include <mozilla-config.h> # include <mozilla-config.h>
#endif #endif
#ifdef XP_UNIX
#ifndef __APPLE__
#include <X11/xpm.h>
#endif
#endif
/* This is from mozilla java, do we really need it? */ /* This is from mozilla java, do we really need it? */
#if 0 #if 0
#include <jri.h> #include <jri.h>
...@@ -53,13 +47,6 @@ ...@@ -53,13 +47,6 @@
#define WINDOW_TEXT "Video is loading..." #define WINDOW_TEXT "Video is loading..."
#ifndef __MAX
# define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
#endif
#ifndef __MIN
# define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
#endif
/***************************************************************************** /*****************************************************************************
* Unix-only declarations * Unix-only declarations
******************************************************************************/ ******************************************************************************/
...@@ -779,62 +766,10 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event ) ...@@ -779,62 +766,10 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
GC gc; GC gc;
XGCValues gcv; XGCValues gcv;
/* Toolbar */
XImage *p_btnPlay = NULL;
XImage *p_btnPause = NULL;
XImage *p_btnStop = NULL;
XImage *p_timeline = NULL;
XImage *p_btnTime = NULL;
XImage *p_btnFullscreen = NULL;
XImage *p_btnMute = NULL;
XImage *p_btnUnmute = NULL;
libvlc_media_instance_t *p_md = NULL;
float f_position = 0;
int i_playing = 0;
bool b_mute = false;
Window video = p_plugin->getVideoWindow(); Window video = p_plugin->getVideoWindow();
Window control = p_plugin->getControlWindow();
Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display; Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
/* load icons */ p_plugin->showToolbar();
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
&p_btnPlay, NULL, NULL);
p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
p_btnPlay->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
&p_btnPause, NULL, NULL);
p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
p_btnPause->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
&p_btnStop, NULL, NULL );
p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
p_btnStop->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
&p_timeline, NULL, NULL);
p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
p_timeline->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
&p_btnTime, NULL, NULL);
p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
p_btnTime->height );
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
&p_btnFullscreen, NULL, NULL);
p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
p_btnFullscreen->height);
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
&p_btnMute, NULL, NULL);
p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
p_btnMute->height);
XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
&p_btnUnmute, NULL, NULL);
p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
p_btnUnmute->height);
if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
!p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
gcv.foreground = BlackPixel( p_display, 0 ); gcv.foreground = BlackPixel( p_display, 0 );
gc = XCreateGC( p_display, video, GCForeground, &gcv ); gc = XCreateGC( p_display, video, GCForeground, &gcv );
...@@ -848,94 +783,11 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event ) ...@@ -848,94 +783,11 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
XDrawString( p_display, video, gc, XDrawString( p_display, video, gc,
window.width / 2 - 40, (window.height - p_plugin->i_control_height) / 2, window.width / 2 - 40, (window.height - p_plugin->i_control_height) / 2,
WINDOW_TEXT, strlen(WINDOW_TEXT) ); WINDOW_TEXT, strlen(WINDOW_TEXT) );
XFreeGC( p_display, gc );
/* RedrawToolbar */ p_plugin->redrawToolbar();
gcv.foreground = BlackPixel( p_display, 0 );
gc = XCreateGC( p_display, control, GCForeground, &gcv );
XFillRectangle( p_display, control, gc,
0, 0, window.width, p_plugin->i_control_height );
gcv.foreground = WhitePixel( p_display, 0 );
XChangeGC( p_display, gc, GCForeground, &gcv );
/* get media instance */
libvlc_exception_t ex;
libvlc_exception_init( &ex );
p_md = libvlc_playlist_get_media_instance( p_plugin->getVLC(), &ex );
libvlc_exception_clear( &ex );
/* get isplaying */
libvlc_exception_init( &ex );
i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
libvlc_exception_clear( &ex );
/* get mute info */
libvlc_exception_init(&ex);
b_mute = libvlc_audio_get_mute( p_plugin->getVLC(), &ex );
libvlc_exception_clear( &ex );
/* get movie position in % */
if( i_playing == 1 )
{
libvlc_exception_init( &ex );
f_position = libvlc_media_instance_get_position(p_md, &ex)*100;
libvlc_exception_clear( &ex );
}
libvlc_media_instance_release(p_md);
/* position icons */
if( p_btnPause && (i_playing == 1) )
{
XPutImage( p_display, control, gc, p_btnPause, 0, 0, 4, 14,
p_btnPause->width, p_btnPause->height );
}
else if( p_btnPlay )
{
XPutImage( p_display, control, gc, p_btnPlay, 0, 0, 4, 14,
p_btnPlay->width, p_btnPlay->height );
}
if( p_btnStop )
XPutImage( p_display, control, gc, p_btnStop, 0, 0, 39, 14,
p_btnStop->width, p_btnStop->height );
if( p_btnFullscreen )
XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, 67, 21,
p_btnFullscreen->width, p_btnFullscreen->height );
if( p_btnUnmute && b_mute )
{
XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, 94, 30,
p_btnUnmute->width, p_btnUnmute->height );
}
else if( p_btnMute )
{
XPutImage( p_display, control, gc, p_btnMute, 0, 0, 94, 30,
p_btnMute->width, p_btnMute->height );
}
if( p_timeline )
XPutImage( p_display, control, gc, p_timeline, 0, 0, 4, 4,
(window.width-8), p_timeline->height );
if( p_btnTime && (f_position > 0) )
{
f_position = (((float)window.width-8)/100)*f_position;
XPutImage( p_display, control, gc, p_btnTime, 0, 0, (4+f_position), 2,
p_btnTime->width, p_btnTime->height );
}
/* Cleanup */
if( p_btnPlay ) XDestroyImage( p_btnPlay );
if( p_btnPause ) XDestroyImage( p_btnPause );
if( p_btnStop ) XDestroyImage( p_btnStop );
if( p_timeline ) XDestroyImage( p_timeline );
if( p_btnTime ) XDestroyImage( p_btnTime );
if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
if( p_btnMute ) XDestroyImage( p_btnMute );
if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
XFreeGC( p_display, gc ); p_plugin->hideToolbar();
} }
static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) static void ControlHandler( Widget w, XtPointer closure, XEvent *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