]> git.sesse.net Git - vlc/commitdiff
Refactor mozilla toolbar code. There are still a few things wrong:
authorJean-Paul Saman <jpsaman@videolan.org>
Mon, 25 Feb 2008 09:22:36 +0000 (09:22 +0000)
committerJean-Paul Saman <jpsaman@videolan.org>
Mon, 25 Feb 2008 09:22:36 +0000 (09:22 +0000)
- nice images
- fix playlist status bug
- timeslider not updated bug
- button/slider position and detection of button click is hardcoded

projects/mozilla/vlcplugin.cpp
projects/mozilla/vlcplugin.h
projects/mozilla/vlcshell.cpp

index 74244e7d39dafd26f143641a29f835c1771a26a7..0d6bf1dab95a1bb946fc63775fc4e43b6a3bc532 100644 (file)
@@ -57,6 +57,7 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
 #if XP_UNIX
     ,i_width((unsigned)-1)
     ,i_height((unsigned)-1)
+    ,i_last_position(0)
 #endif
 {
     memset(&npwindow, 0, sizeof(NPWindow));
@@ -443,5 +444,169 @@ int  VlcPlugin::setSize(unsigned width, unsigned height)
     /* return size */
     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
index 81475942973175fb14e5159f5f9048a35d375477..645dfe82875cd9c67fbf52c47ead59a230cf4848 100644 (file)
 #   include <X11/Intrinsic.h>
 #   include <X11/StringDefs.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
 
 class VlcPlugin
@@ -96,6 +107,10 @@ public:
                             { return npcontrol; };
     void                setControlWindow(Window window)
                             { npcontrol = window; };
+
+    void                showToolbar();
+    void                hideToolbar();
+    void                redrawToolbar();
 #endif
 
     uint16    i_npmode; /* either NP_EMBED or NP_FULL */
@@ -128,6 +143,16 @@ private:
     unsigned int     i_width, i_height;
     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
 };
 
index 9a0a4d5daf8864fde9390d2ebc4c75bc59a25466..66a73e5d1144d1abd8ac4cdc1b09074c265bfbf6 100644 (file)
 #   include <mozilla-config.h>
 #endif
 
-#ifdef XP_UNIX
-#ifndef __APPLE__
-#include <X11/xpm.h>
-#endif
-#endif
-
 /* This is from mozilla java, do we really need it? */
 #if 0
 #include <jri.h>
 
 #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
 ******************************************************************************/
@@ -779,62 +766,10 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
     GC gc;
     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 control = p_plugin->getControlWindow();
     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
 
-    /* load icons */
-    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 );
+    p_plugin->showToolbar();
 
     gcv.foreground = BlackPixel( p_display, 0 );
     gc = XCreateGC( p_display, video, GCForeground, &gcv );
@@ -848,94 +783,11 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
     XDrawString( p_display, video, gc,
                  window.width / 2 - 40, (window.height - p_plugin->i_control_height) / 2,
                  WINDOW_TEXT, strlen(WINDOW_TEXT) );
+    XFreeGC( p_display, gc );
 
-    /* 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 );
+    p_plugin->redrawToolbar();
 
-    XFreeGC( p_display, gc );
+    p_plugin->hideToolbar();
 }
 
 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )