]> git.sesse.net Git - vlc/commitdiff
* skins/controls/button.cpp: Fixed a nasty bug.
authorOlivier Teulière <ipkiss@videolan.org>
Sat, 31 May 2003 23:23:59 +0000 (23:23 +0000)
committerOlivier Teulière <ipkiss@videolan.org>
Sat, 31 May 2003 23:23:59 +0000 (23:23 +0000)
 * skins/controls/generic.h: Some public fields are now protected
 * skins/src/window.cpp:
    - Added a few debug messages
    - Invisible controls don't receive events anymore

Note: There are still a few bugs in the code handling the controls and
their different states, and I think they will be difficult to fix with
the current code structure. A rewrite of this part of code could be a
good idea (perhaps using states and transitions between states, like
Zinf does?).

modules/gui/skins/controls/button.cpp
modules/gui/skins/controls/generic.cpp
modules/gui/skins/controls/generic.h
modules/gui/skins/controls/playlist.cpp
modules/gui/skins/controls/playlist.h
modules/gui/skins/src/event.cpp
modules/gui/skins/src/window.cpp

index a75fcf3bde6836736fcf054ae5bbb6dc07c2a15e..6d75b6306e14b90dbd46c4b2d9dbf4b7899eb515 100644 (file)
@@ -2,7 +2,7 @@
  * button.cpp: Button control
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: button.cpp,v 1.13 2003/05/26 02:09:27 gbazin Exp $
+ * $Id: button.cpp,v 1.14 2003/05/31 23:23:59 ipkiss Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -52,7 +52,7 @@ ControlButton::ControlButton(
     // General
     Left            = x;
     Top             = y;
-    State           = 1;                   // 1 = up - 0 = down
+    State           = 1;                   // 1=up, 0=down
     Selected        = false;
     Enabled         = true;
     CursorIn        = false;
@@ -135,6 +135,9 @@ void ControlButton::Draw( int x, int y, int w, int h, Graphics *dest )
 bool ControlButton::MouseUp( int x, int y, int button )
 {
     // If hit in the button
+    // XXX: we suppose here that the expected behaviour is to have the MouseUp
+    // event above the "up" image, and not above the "down" one. This can give
+    // strange results when the "up" and "down" images have different sizes...
     if( Img[1]->Hit( x - Left, y - Top ) )
     {
         if( !Enabled )
@@ -180,7 +183,6 @@ bool ControlButton::MouseMove( int x, int y, int button )
     if( !Enabled )
         return false;
 
-
     if( MouseOver( x, y ) && !CursorIn )
     {
         if( button == 1 && Selected )
@@ -197,9 +199,8 @@ bool ControlButton::MouseMove( int x, int y, int button )
         CursorIn = true;
         return true;
     }
-    else if( !MouseOver( x, y ) & CursorIn )
+    else if( !MouseOver( x, y ) && CursorIn )
     {
-
         if( button == 1 && Selected )
         {
             State = 1;
index 0a629a1eafef62bedd820e6de02504bf041f92e8..e30ee2bdc42eba40fd282960b2c4f10461c4a43c 100644 (file)
@@ -2,7 +2,7 @@
  * generic.cpp: Generic control, parent of the others
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: generic.cpp,v 1.6 2003/04/28 12:25:34 asmax Exp $
+ * $Id: generic.cpp,v 1.7 2003/05/31 23:23:59 ipkiss Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -104,18 +104,6 @@ bool GenericControl::GenericProcessEvent( Event *evt )
 
 }
 //---------------------------------------------------------------------------
-bool GenericControl::IsID( string id )
-{
-    if( ID == "none" || ID != id )
-    {
-        return false;
-    }
-    else
-    {
-        return true;
-    }
-}
-//---------------------------------------------------------------------------
 void GenericControl::Init()
 {
 }
index f89ec2f95a4bee46ed6ef4c7ab6b536a5df0e485..740e41e02f818dec798a6a936b9ada42dcbb546b 100644 (file)
@@ -2,7 +2,7 @@
  * generic.h: Generic control, parent of the others
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: generic.h,v 1.4 2003/04/28 12:25:34 asmax Exp $
+ * $Id: generic.h,v 1.5 2003/05/31 23:23:59 ipkiss Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -46,15 +46,23 @@ class GenericControl               // This is the generic control class
 {
     protected:
         SkinWindow * ParentWindow;
+        intf_thread_t *p_intf;
         bool     Visible;
         string   ID;
         string   Help;
-        intf_thread_t *p_intf;
+        int Left;               // Left offset of the control
+        int Top;                // Top offset of the control
+        int Width;              // Width of the control
+        int Height;             // Height of the control
+        int State;              // Used to special state of the control
+                                // (for button, sets whether down or up)
+        Bitmap **Img;           // Array of bitmap used to draw control
 
     private:
     public:
         // Constructor
-        GenericControl( string id, bool visible, string help, SkinWindow *Parent );
+        GenericControl( string id, bool visible, string help,
+                        SkinWindow *Parent );
 
         // Destructor
         virtual ~GenericControl();
@@ -87,19 +95,19 @@ class GenericControl               // This is the generic control class
 
         // Create a region from a bitmap with transcolor as empty region
         SkinRegion *CreateRegionFromBmp( Bitmap *bmp, int MoveX, int MoveY );
-        int Left;               // Left offset of the control
-        int Top;                // Top offset of the control
-        int Width;              // Width of the control
-        int Height;             // Height of the control
-        int State;              // Used to special state of the control
-                                // (for button, sets whether down or up)
-        Bitmap **Img;           // Array of bitmap used to draw control
 
         // Enabling control
         virtual void Enable( Event *event, bool enabled );
 
-        // Found if ID matches
-        bool IsID( string id );
+        // Self explanatory
+        bool IsVisible()    { return Visible; }
+
+        // Getters
+        string GetId()      { return ID; }
+        int GetLeft()       { return Left; }
+        int GetTop()        { return Top; }
+        int GetWidth()      { return Width; }
+        int GetHeight()     { return Height; }
 };
 //---------------------------------------------------------------------------
 
index 08d31849c1e6af96e3326993f2ed94fc8a722a80..91a1a3c36efcef2d3cd0cbadf315f8f33971ff97 100644 (file)
@@ -2,7 +2,7 @@
  * playlist.cpp: Playlist control
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: playlist.cpp,v 1.10 2003/04/28 12:25:34 asmax Exp $
+ * $Id: playlist.cpp,v 1.11 2003/05/31 23:23:59 ipkiss Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -170,10 +170,10 @@ void ControlPlayList::Init()
     delete[] y;
 
     // Get size of control
-    Left   = Slider->Left;
-    Top    = Slider->Top;
-    Width  = Slider->Left + Slider->Width;
-    Height = Slider->Top  + Slider->Height;
+    Left   = Slider->GetLeft();
+    Top    = Slider->GetTop();
+    Width  = Slider->GetLeft() + Slider->GetWidth();
+    Height = Slider->GetTop()  + Slider->GetHeight();
     if( TextLeft < Left )
         Left = TextLeft;
     if( TextTop  < Top  )
index 11c7d943b029182ee1ad8a5b9bc4677b55e3fded..62afc8475d3bba46fb76a113d9f4e2ce3026c777 100644 (file)
@@ -2,7 +2,7 @@
  * playlist.h: Playlist control
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: playlist.h,v 1.5 2003/04/28 12:25:34 asmax Exp $
+ * $Id: playlist.h,v 1.6 2003/05/31 23:23:59 ipkiss Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -47,8 +47,8 @@ class ControlPlayList : public GenericControl
 {
     private:
         Event      *UpdateEvent;
-        SkinFont       *TextFont;
-        SkinFont       *PlayFont;
+        SkinFont   *TextFont;
+        SkinFont   *PlayFont;
         string      FontName;
         string      PlayFontName;
         bool        Enabled;
index ad36ad9ac0d97fb87828037df351ea2ea3c1b194..99332a4b8d1eb6598837b8ea26fe9e575843dfd9 100644 (file)
@@ -2,7 +2,7 @@
  * event.cpp: Event class
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: event.cpp,v 1.15 2003/05/05 16:29:57 gbazin Exp $
+ * $Id: event.cpp,v 1.16 2003/05/31 23:23:59 ipkiss Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -176,7 +176,7 @@ unsigned int Event::GetMessageType( string Desc )
     else if( Desc == "VLC_NET_ADDUDP" )
         return VLC_NET_ADDUDP;
 
-    // Window event
+    // Window events
     else if( Desc == "WINDOW_MOVE" )
         return WINDOW_MOVE;
     else if( Desc == "WINDOW_OPEN" )
@@ -190,7 +190,7 @@ unsigned int Event::GetMessageType( string Desc )
     else if( Desc == "WINDOW_FADE" )
         return WINDOW_FADE;
 
-    // Control event
+    // Control events
     else if( Desc == "CTRL_ENABLED" )
         return CTRL_ENABLED;
     else if( Desc == "CTRL_VISIBLE" )
@@ -203,7 +203,7 @@ unsigned int Event::GetMessageType( string Desc )
         return CTRL_SET_SLIDER;
 
 
-    // Control event by ID
+    // Control events by ID
     else if( Desc == "CTRL_ID_VISIBLE" )
         return CTRL_ID_VISIBLE;
     else if( Desc == "CTRL_ID_ENABLED" )
@@ -347,7 +347,7 @@ GenericControl * Event::FindControl( string id )
     {
         for( i = 0; i < (*win)->ControlList.size(); i++ )
         {
-            if( (*win)->ControlList[i]->IsID( id ) )
+            if( (*win)->ControlList[i]->GetId() == id )
                 return (*win)->ControlList[i];
         }
     }
index e2595a30eeb67e56491eee8a39b408a6799da1e8..c1c4cbf692b8baa38573d92f9463eaf73752db2e 100644 (file)
@@ -2,7 +2,7 @@
  * window.cpp: Window class
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: window.cpp,v 1.24 2003/05/26 02:09:27 gbazin Exp $
+ * $Id: window.cpp,v 1.25 2003/05/31 23:23:59 ipkiss Exp $
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
@@ -294,8 +294,8 @@ void SkinWindow::RefreshImage( int x, int y, int w, int h )
 //    Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
 
     // Draw every control
-        for( i = 0; i < ControlList.size(); i++ )
-            ControlList[i]->Draw( x, y, w, h, Buffer );
+    for( i = 0; i < ControlList.size(); i++ )
+        ControlList[i]->Draw( x, y, w, h, Buffer );
 
     // Copy buffer in Image
     Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY );
@@ -317,7 +317,6 @@ void SkinWindow::Refresh( int x, int y, int w, int h )
 
     // And copy buffer to window
     RefreshFromImage( x, y, w, h );
-
 }
 //---------------------------------------------------------------------------
 void SkinWindow::RefreshAll()
@@ -327,16 +326,17 @@ void SkinWindow::RefreshAll()
 //---------------------------------------------------------------------------
 void SkinWindow::MouseDown( int x, int y, int button )
 {
-
     // Checking event in controls
-    for( int i = ControlList.size() - 1; i >= 0 ; i-- )
+    for( int i = ControlList.size() - 1; i >= 0; i-- )
     {
-        if( ControlList[i]->MouseDown( x, y, button ) )
+        if( ControlList[i]->IsVisible() &&
+            ControlList[i]->MouseDown( x, y, button ) )
         {
-            return;
+            msg_Dbg( p_intf, "Mouse down (ID=%s)",
+                     ControlList[i]->GetId().c_str() );
+            break;
         }
     }
-
 }
 //---------------------------------------------------------------------------
 void SkinWindow::MouseMove( int x, int y, int button  )
@@ -350,20 +350,22 @@ void SkinWindow::MouseMove( int x, int y, int button  )
     }
 
     // Checking event in controls
-    for( i = ControlList.size() - 1; i >= 0 ; i-- )
+    for( i = ControlList.size() - 1; i >= 0; i-- )
     {
-        ControlList[i]->MouseMove( x, y, button );
+        if( ControlList[i]->IsVisible() &&
+            ControlList[i]->MouseMove( x, y, button ) )
+        {
+            break;
+        }
     }
 
     // Checking help text
-    for( i = ControlList.size() - 1; i >= 0 ; i-- )
+    for( i = ControlList.size() - 1; i >= 0; i-- )
     {
-        if( ControlList[i]->MouseOver( x, y ) )
+        if( ControlList[i]->IsVisible() && ControlList[i]->MouseOver( x, y ) )
         {
-            if( ControlList[i]->SendNewHelpText() )
-            {
-                break;
-            }
+            ControlList[i]->SendNewHelpText();
+            break;
         }
     }
 
@@ -375,10 +377,13 @@ void SkinWindow::MouseMove( int x, int y, int button  )
     }
 
     // Checking for change in Tool Tip
-    for( i = ControlList.size() - 1; i >= 0 ; i-- )
+    for( i = ControlList.size() - 1; i >= 0; i-- )
     {
-        if( ControlList[i]->ToolTipTest( x, y ) )
+        if( ControlList[i]->IsVisible() &&
+            ControlList[i]->ToolTipTest( x, y ) )
+        {
             break;
+        }
     }
 
     // If no change, delete tooltip text
@@ -403,11 +408,14 @@ void SkinWindow::MouseUp( int x, int y, int button )
     }
 
     // Checking event in controls
-    for( i = ControlList.size() - 1; i >= 0 ; i-- )
+    for( i = ControlList.size() - 1; i >= 0; i-- )
     {
-        if( ControlList[i]->MouseUp( x, y, button ) )
+        if( ControlList[i]->IsVisible() &&
+            ControlList[i]->MouseUp( x, y, button ) )
         {
-            return;
+            msg_Dbg( p_intf, "Mouse up (ID=%s)",
+                     ControlList[i]->GetId().c_str() );
+            break;
         }
     }
 }
@@ -417,21 +425,26 @@ void SkinWindow::MouseDblClick( int x, int y, int button )
     int i;
 
     // Checking event in controls
-    for( i = ControlList.size() - 1; i >= 0 ; i-- )
+    for( i = ControlList.size() - 1; i >= 0; i-- )
     {
-        if( ControlList[i]->MouseDblClick( x, y, button ) )
-            return;
+        if( ControlList[i]->IsVisible() &&
+            ControlList[i]->MouseDblClick( x, y, button ) )
+        {
+            msg_Dbg( p_intf, "Double click (ID=%s)",
+                     ControlList[i]->GetId().c_str() );
+        }
     }
 }
 //---------------------------------------------------------------------------
 void SkinWindow::MouseScroll( int x, int y, int direction )
 {
     // Checking event in controls
-    for( int i = ControlList.size() - 1; i >= 0 ; i-- )
+    for( int i = ControlList.size() - 1; i >= 0; i-- )
     {
-        if( ControlList[i]->MouseScroll( x, y, direction ) )
+        if( ControlList[i]->IsVisible() &&
+            ControlList[i]->MouseScroll( x, y, direction ) )
         {
-            return;
+            break;
         }
     }
 }
@@ -462,10 +475,10 @@ void SkinWindow::ReSize()
     {
 #define min(a,b) ((a)<(b))?(a):(b)
 #define max(a,b) ((a)>(b))?(a):(b)
-        w    = max( w,    ControlList[i]->Left + ControlList[i]->Width );
-        h    = max( h,    ControlList[i]->Top + ControlList[i]->Height );
-        MinX = min( MinX, ControlList[i]->Left );
-        MinY = min( MinY, ControlList[i]->Top );
+        w = max( w, ControlList[i]->GetLeft() + ControlList[i]->GetWidth() );
+        h = max( h, ControlList[i]->GetTop() + ControlList[i]->GetHeight() );
+        MinX = min( MinX, ControlList[i]->GetLeft() );
+        MinY = min( MinY, ControlList[i]->GetTop() );
 #undef max
 #undef min
     }