]> git.sesse.net Git - vlc/commitdiff
* src/vlcproc.cpp: DO NOT update the GUI directly from the vlc callbacks,
authorCyril Deguet <asmax@videolan.org>
Sat, 3 Apr 2004 13:57:46 +0000 (13:57 +0000)
committerCyril Deguet <asmax@videolan.org>
Sat, 3 Apr 2004 13:57:46 +0000 (13:57 +0000)
  skins are not reentrant (at least with x11). Put commands in the queue
  instead.
  * commands/cmd_vars: commands to change variables
  * controls/ctrl_list.cpp: automatic scroll when the stream changes
  * src/bitmap.cpp: removed the scandinavian characters from the
    text font, they don't belong to ASCII (caused a stack corruption)

modules/gui/skins2/Modules.am
modules/gui/skins2/commands/cmd_vars.cpp [moved from modules/gui/skins2/commands/cmd_notify_playlist.cpp with 84% similarity]
modules/gui/skins2/commands/cmd_vars.hpp [moved from modules/gui/skins2/commands/cmd_notify_playlist.hpp with 56% similarity]
modules/gui/skins2/controls/ctrl_list.cpp
modules/gui/skins2/controls/ctrl_list.hpp
modules/gui/skins2/src/bitmap_font.cpp
modules/gui/skins2/src/ft2_font.cpp
modules/gui/skins2/src/vlcproc.cpp
modules/gui/skins2/vars/stream.hpp

index d09f95734f9b032bd1846f50aa7c849165fd1f85..be8bc23672bbbb6a71801f44107bbe82e1e55994 100644 (file)
@@ -14,8 +14,6 @@ SOURCES_skins2 = \
        commands/cmd_input.hpp \
        commands/cmd_layout.cpp \
        commands/cmd_layout.hpp \
-       commands/cmd_notify_playlist.cpp \
-       commands/cmd_notify_playlist.hpp \
        commands/cmd_on_top.cpp \
        commands/cmd_on_top.hpp \
        commands/cmd_playlist.cpp \
@@ -25,6 +23,8 @@ SOURCES_skins2 = \
        commands/cmd_resize.cpp \
        commands/cmd_resize.hpp \
        commands/cmd_show_window.hpp \
+       commands/cmd_vars.cpp \
+       commands/cmd_vars.hpp \
        \
        controls/ctrl_button.cpp \
        controls/ctrl_button.hpp \
similarity index 84%
rename from modules/gui/skins2/commands/cmd_notify_playlist.cpp
rename to modules/gui/skins2/commands/cmd_vars.cpp
index 92c1b1762e7a7753e9e447e3328e815894bf1f65..3aa169a52e43f378b070114a43498575082c639e 100644 (file)
@@ -1,11 +1,10 @@
 /*****************************************************************************
- * cmd_notify_playlist.cpp
+ * cmd_vars.cpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
- * $Id: cmd_notify_playlist.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
+ * Copyright (C) 2004 VideoLAN
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,8 +21,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#include "cmd_notify_playlist.hpp"
+#include "cmd_vars.hpp"
 #include "../src/vlcproc.hpp"
+#include "../vars/stream.hpp"
 #include "../vars/playlist.hpp"
 
 
@@ -33,3 +33,11 @@ void CmdNotifyPlaylist::execute()
     Playlist &rVar = VlcProc::instance( getIntf() )->getPlaylistVar();
     rVar.onChange();
 }
+
+
+void CmdSetStream::execute()
+{
+    // Change the stream variable
+    m_rStream.set( m_name, m_updateVLC );
+}
+
similarity index 56%
rename from modules/gui/skins2/commands/cmd_notify_playlist.hpp
rename to modules/gui/skins2/commands/cmd_vars.hpp
index 074af4937d96df708234be371b82e4d82c8614a4..0d2708c90573ed2f5f00465869394d42d31bcac1 100644 (file)
@@ -1,11 +1,10 @@
 /*****************************************************************************
- * cmd_notify_playlist.hpp
+ * cmd_vars.hpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
- * $Id: cmd_notify_playlist.hpp,v 1.2 2004/01/05 22:17:32 asmax Exp $
+ * Copyright (C) 2004 VideoLAN
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#ifndef CMD_NOTIFY_PLAYLIST_HPP
-#define CMD_NOTIFY_PLAYLIST_HPP
+#ifndef CMD_VARS_HPP
+#define CMD_VARS_HPP
 
 #include "cmd_generic.hpp"
+#include "../utils/ustring.hpp"
 
+class Stream;
 
 /// Command to notify the playlist of a change
 DEFINE_COMMAND( NotifyPlaylist, "notify playlist" )
 
+
+/// Command to set a stream variable
+class CmdSetStream: public CmdGeneric
+{
+    public:
+        CmdSetStream( intf_thread_t *pIntf, Stream &rStream,
+                      const UString &rName, bool updateVLC ):
+            CmdGeneric( pIntf ), m_rStream( rStream ), m_name( rName ),
+            m_updateVLC( updateVLC ) {}
+        virtual ~CmdSetStream() {}
+
+        /// This method does the real job of the command
+        virtual void execute();
+
+        /// Return the type of the command
+        virtual string getType() const { return "set stream"; }
+
+    private:
+        /// Stream variable to set
+        Stream &m_rStream;
+        /// Value to set
+        const UString m_name;
+        bool m_updateVLC;
+};
+
+
 #endif
index 722c77ae74dbb4f4dacd191368c56949e649ebed..c6d7d50867f37bd3cd59809bf38abd631affbd4d 100644 (file)
@@ -72,8 +72,7 @@ CtrlList::~CtrlList()
 
 void CtrlList::onUpdate( Subject<VarList> &rList )
 {
-    makeImage();
-    notifyLayout();
+    autoScroll();
     m_pLastSelected = NULL;
 }
 
@@ -324,6 +323,47 @@ void CtrlList::draw( OSGraphics &rImage, int xDest, int yDest )
 }
 
 
+void CtrlList::autoScroll()
+{
+    // Get the size of the control
+    const Position *pPos = getPosition();
+    if( !pPos )
+    {
+        return;
+    }
+    int height = pPos->getHeight();
+
+    // How many lines can be displayed ?
+    int itemHeight = m_rFont.getSize() + LINE_INTERVAL;
+    int maxItems = height / itemHeight;
+
+    // Find the current playing stream
+    int playIndex = 0;
+    VarList::ConstIterator it;
+    for( it = m_rList.begin(); it != m_rList.end(); it++ )
+    {
+        if( (*it).m_playing )
+        {
+            break;
+        }
+        playIndex++;
+    }
+    if( it != m_rList.end() &&
+        ( playIndex < m_lastPos || playIndex >= m_lastPos + maxItems ) )
+    {
+        // Scroll the list to have the playing stream visible
+        VarPercent &rVarPos = m_rList.getPositionVar();
+        rVarPos.set( 1.0 - (float)playIndex / (float)m_rList.size() );
+        // The image will be changed by onUpdate(VarPercent&)
+    }
+    else
+    {
+        makeImage();
+        notifyLayout();
+    }
+}
+
+
 void CtrlList::makeImage()
 {
     if( m_pImage )
index ae84d7049c1b6a2cee531894647d6747480c9e1b..8d552d07413e9dab41f78cf95b00e9edff7f6163 100644 (file)
@@ -2,7 +2,7 @@
  * ctrl_list.hpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: ctrl_list.hpp,v 1.2 2004/02/29 16:49:55 asmax Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -88,6 +88,9 @@ class CtrlList: public CtrlGeneric, public Observer<VarList>,
         /// Called when the position is set
         virtual void onPositionChange();
 
+        /// Check if the list must be scrolled
+        void autoScroll();
+
         /// Draw the image of the control
         void makeImage();
 };
index 66a2fec916916a64db767a84836e5e8e67ceee48..55d3a19a9c559f28b0b6881b45f405cb255642b2 100644 (file)
@@ -69,17 +69,9 @@ BitmapFont::BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
             m_table[(size_t)specialChars[i]].m_xPos = (11 + i) * m_width;
             m_table[(size_t)specialChars[i]].m_yPos = m_height;
         }
-        m_table[(size_t)'Å'].m_xPos = m_table[(size_t)'å'].m_xPos = 0;
-        m_table[(size_t)'Ö'].m_xPos = m_table[(size_t)'ö'].m_xPos = m_width;
-        m_table[(size_t)'Ä'].m_xPos = m_table[(size_t)'ä'].m_xPos = 3 * m_width;
         m_table[(size_t)'?'].m_xPos = 4 * m_width;
         m_table[(size_t)'*'].m_xPos = 5 * m_width;
-        static const char thirdLine[] = {'Å', 'å', 'Ö', 'ö', 'Ä', 'ä', '?',
-            '*'};
-        for( int i = 0; i < 8; i++ )
-        {
-            m_table[(size_t)thirdLine[i]].m_yPos = 2 * m_height;
-        }
+        m_table[(size_t)'?'].m_yPos = m_table[(size_t)'*'].m_yPos = 2 * m_height;
     }
 }
 
index 020ea793f5c45ac24e9cbbb5a469434de460c77e..fa3eae2871aa369a39af40724f8096a887459225 100644 (file)
@@ -238,8 +238,8 @@ GenericBitmap *FT2Font::drawString( const UString &rString, uint32_t color,
     }
 
     // Adjust the size for vertical padding
-    yMax == __MAX( yMax, m_ascender );
-    yMin == __MIN( yMin, m_descender );
+    yMax = __MAX( yMax, m_ascender );
+    yMin = __MIN( yMin, m_descender );
 
     // Create the bitmap
     FT2Bitmap *pBmp = new FT2Bitmap( getIntf(), __MIN( width1, width2 ),
index 52da3f38d65984d15989958ff58d8d624a6c8568..f038de29c5b1834b8c0e5021f406dc5da6077cd9 100755 (executable)
@@ -29,8 +29,8 @@
 #include "os_timer.hpp"
 #include "var_manager.hpp"
 #include "../commands/async_queue.hpp"
-#include "../commands/cmd_notify_playlist.hpp"
 #include "../commands/cmd_quit.hpp"
+#include "../commands/cmd_vars.hpp"
 #include "../utils/var_bool.hpp"
 
 
@@ -82,6 +82,11 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf )
     REGISTER_VAR( m_cVarSeekable, VarBoolImpl, "vlc.isSeekable" )
 #undef REGISTER_VAR
 
+    // XXX WARNING XXX
+    // The object variable callbacks are called from other VLC threads,
+    // so they must put commands in the queue and NOT do anything else
+    // (X11 calls are not reentrant)
+
     // Called when the playlist changes
     var_AddCallback( pIntf->p_sys->p_playlist, "intf-change",
                      onIntfChange, this );
@@ -226,8 +231,7 @@ int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
     AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
     pQueue->remove( "notify playlist" );
     pQueue->push( CmdGenericPtr( pCmd ) );
-/*
-    p_playlist_dialog->UpdateItem( new_val.i_int );*/
+
     return VLC_SUCCESS;
 }
 
@@ -238,16 +242,22 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
 {
     VlcProc *pThis = ( VlcProc* )pParam;
 
-    // Update the stream variable
-    // XXX: we should not need to access p_inpu->psz_source directly, a
-    // getter should be provided by VLC core
+    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
+
     playlist_t *p_playlist = (playlist_t*)pObj;
     if( p_playlist->p_input )
     {
+        // Create a command to update the stream variable
+        // XXX: we should not need to access p_inpu->psz_source directly, a
+        // getter should be provided by VLC core
         Stream *pStream = (Stream*)pThis->m_cVarStream.get();
         UString srcName( pThis->getIntf(),
                          p_playlist->p_input->psz_source );
-        pStream->set( srcName, false );
+        CmdSetStream *pCmd = new CmdSetStream( pThis->getIntf(), *pStream,
+                                               srcName, false );
+        // Push the command in the asynchronous command queue
+        pQueue->remove( "set stream" );
+        pQueue->push( CmdGenericPtr( pCmd ) );
     }
 
     // Create a playlist notify command
@@ -255,12 +265,9 @@ int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
     CmdNotifyPlaylist *pCmd = new CmdNotifyPlaylist( pThis->getIntf() );
 
     // Push the command in the asynchronous command queue
-    AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
     pQueue->remove( "notify playlist" );
     pQueue->push( CmdGenericPtr( pCmd ) );
 
-//     p_playlist_dialog->UpdateItem( old_val.i_int );
-//     p_playlist_dialog->UpdateItem( new_val.i_int );
     return VLC_SUCCESS;
 }
 
index 92371d21f96d2209cf1a0a45ddc6a76bdf7d1ce5..4c65407265ca8d6384ab01bc919f1236d3a029c9 100644 (file)
@@ -29,7 +29,7 @@
 
 class UString;
 
-/// Variable for VLC volume
+/// Variable for VLC stream name
 class Stream: public VarText
 {
     public: