Commit 7643c27b authored by Olivier Teulière's avatar Olivier Teulière

* skins/controls/button.cpp: Fixed a nasty bug.

 * 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?).
parent cf9cdcac
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* button.cpp: Button control * button.cpp: Button control
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * 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 Teulire <ipkiss@via.ecp.fr> * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr>
...@@ -52,7 +52,7 @@ ControlButton::ControlButton( ...@@ -52,7 +52,7 @@ ControlButton::ControlButton(
// General // General
Left = x; Left = x;
Top = y; Top = y;
State = 1; // 1 = up - 0 = down State = 1; // 1=up, 0=down
Selected = false; Selected = false;
Enabled = true; Enabled = true;
CursorIn = false; CursorIn = false;
...@@ -135,6 +135,9 @@ void ControlButton::Draw( int x, int y, int w, int h, Graphics *dest ) ...@@ -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 ) bool ControlButton::MouseUp( int x, int y, int button )
{ {
// If hit in the 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( Img[1]->Hit( x - Left, y - Top ) )
{ {
if( !Enabled ) if( !Enabled )
...@@ -180,7 +183,6 @@ bool ControlButton::MouseMove( int x, int y, int button ) ...@@ -180,7 +183,6 @@ bool ControlButton::MouseMove( int x, int y, int button )
if( !Enabled ) if( !Enabled )
return false; return false;
if( MouseOver( x, y ) && !CursorIn ) if( MouseOver( x, y ) && !CursorIn )
{ {
if( button == 1 && Selected ) if( button == 1 && Selected )
...@@ -197,9 +199,8 @@ bool ControlButton::MouseMove( int x, int y, int button ) ...@@ -197,9 +199,8 @@ bool ControlButton::MouseMove( int x, int y, int button )
CursorIn = true; CursorIn = true;
return true; return true;
} }
else if( !MouseOver( x, y ) & CursorIn ) else if( !MouseOver( x, y ) && CursorIn )
{ {
if( button == 1 && Selected ) if( button == 1 && Selected )
{ {
State = 1; State = 1;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* generic.cpp: Generic control, parent of the others * generic.cpp: Generic control, parent of the others
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * 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 Teulire <ipkiss@via.ecp.fr> * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr>
...@@ -104,18 +104,6 @@ bool GenericControl::GenericProcessEvent( Event *evt ) ...@@ -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() void GenericControl::Init()
{ {
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* generic.h: Generic control, parent of the others * generic.h: Generic control, parent of the others
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * 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> * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr>
...@@ -46,15 +46,23 @@ class GenericControl // This is the generic control class ...@@ -46,15 +46,23 @@ class GenericControl // This is the generic control class
{ {
protected: protected:
SkinWindow * ParentWindow; SkinWindow * ParentWindow;
intf_thread_t *p_intf;
bool Visible; bool Visible;
string ID; string ID;
string Help; 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: private:
public: public:
// Constructor // Constructor
GenericControl( string id, bool visible, string help, SkinWindow *Parent ); GenericControl( string id, bool visible, string help,
SkinWindow *Parent );
// Destructor // Destructor
virtual ~GenericControl(); virtual ~GenericControl();
...@@ -87,19 +95,19 @@ class GenericControl // This is the generic control class ...@@ -87,19 +95,19 @@ class GenericControl // This is the generic control class
// Create a region from a bitmap with transcolor as empty region // Create a region from a bitmap with transcolor as empty region
SkinRegion *CreateRegionFromBmp( Bitmap *bmp, int MoveX, int MoveY ); 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 // Enabling control
virtual void Enable( Event *event, bool enabled ); virtual void Enable( Event *event, bool enabled );
// Found if ID matches // Self explanatory
bool IsID( string id ); 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; }
}; };
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* playlist.cpp: Playlist control * playlist.cpp: Playlist control
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * 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 Teulire <ipkiss@via.ecp.fr> * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr>
...@@ -170,10 +170,10 @@ void ControlPlayList::Init() ...@@ -170,10 +170,10 @@ void ControlPlayList::Init()
delete[] y; delete[] y;
// Get size of control // Get size of control
Left = Slider->Left; Left = Slider->GetLeft();
Top = Slider->Top; Top = Slider->GetTop();
Width = Slider->Left + Slider->Width; Width = Slider->GetLeft() + Slider->GetWidth();
Height = Slider->Top + Slider->Height; Height = Slider->GetTop() + Slider->GetHeight();
if( TextLeft < Left ) if( TextLeft < Left )
Left = TextLeft; Left = TextLeft;
if( TextTop < Top ) if( TextTop < Top )
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* playlist.h: Playlist control * playlist.h: Playlist control
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * 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 Teulire <ipkiss@via.ecp.fr> * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr>
...@@ -47,8 +47,8 @@ class ControlPlayList : public GenericControl ...@@ -47,8 +47,8 @@ class ControlPlayList : public GenericControl
{ {
private: private:
Event *UpdateEvent; Event *UpdateEvent;
SkinFont *TextFont; SkinFont *TextFont;
SkinFont *PlayFont; SkinFont *PlayFont;
string FontName; string FontName;
string PlayFontName; string PlayFontName;
bool Enabled; bool Enabled;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* event.cpp: Event class * event.cpp: Event class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * 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 Teulire <ipkiss@via.ecp.fr> * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr>
...@@ -176,7 +176,7 @@ unsigned int Event::GetMessageType( string Desc ) ...@@ -176,7 +176,7 @@ unsigned int Event::GetMessageType( string Desc )
else if( Desc == "VLC_NET_ADDUDP" ) else if( Desc == "VLC_NET_ADDUDP" )
return VLC_NET_ADDUDP; return VLC_NET_ADDUDP;
// Window event // Window events
else if( Desc == "WINDOW_MOVE" ) else if( Desc == "WINDOW_MOVE" )
return WINDOW_MOVE; return WINDOW_MOVE;
else if( Desc == "WINDOW_OPEN" ) else if( Desc == "WINDOW_OPEN" )
...@@ -190,7 +190,7 @@ unsigned int Event::GetMessageType( string Desc ) ...@@ -190,7 +190,7 @@ unsigned int Event::GetMessageType( string Desc )
else if( Desc == "WINDOW_FADE" ) else if( Desc == "WINDOW_FADE" )
return WINDOW_FADE; return WINDOW_FADE;
// Control event // Control events
else if( Desc == "CTRL_ENABLED" ) else if( Desc == "CTRL_ENABLED" )
return CTRL_ENABLED; return CTRL_ENABLED;
else if( Desc == "CTRL_VISIBLE" ) else if( Desc == "CTRL_VISIBLE" )
...@@ -203,7 +203,7 @@ unsigned int Event::GetMessageType( string Desc ) ...@@ -203,7 +203,7 @@ unsigned int Event::GetMessageType( string Desc )
return CTRL_SET_SLIDER; return CTRL_SET_SLIDER;
// Control event by ID // Control events by ID
else if( Desc == "CTRL_ID_VISIBLE" ) else if( Desc == "CTRL_ID_VISIBLE" )
return CTRL_ID_VISIBLE; return CTRL_ID_VISIBLE;
else if( Desc == "CTRL_ID_ENABLED" ) else if( Desc == "CTRL_ID_ENABLED" )
...@@ -347,7 +347,7 @@ GenericControl * Event::FindControl( string id ) ...@@ -347,7 +347,7 @@ GenericControl * Event::FindControl( string id )
{ {
for( i = 0; i < (*win)->ControlList.size(); i++ ) for( i = 0; i < (*win)->ControlList.size(); i++ )
{ {
if( (*win)->ControlList[i]->IsID( id ) ) if( (*win)->ControlList[i]->GetId() == id )
return (*win)->ControlList[i]; return (*win)->ControlList[i];
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* window.cpp: Window class * window.cpp: Window class
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * 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 Teulire <ipkiss@via.ecp.fr> * Authors: Olivier Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr> * Emmanuel Puig <karibu@via.ecp.fr>
...@@ -294,8 +294,8 @@ void SkinWindow::RefreshImage( int x, int y, int w, int h ) ...@@ -294,8 +294,8 @@ void SkinWindow::RefreshImage( int x, int y, int w, int h )
// Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this ); // Graphics *Buffer = (Graphics *)new OSGraphics( w, h, this );
// Draw every control // Draw every control
for( i = 0; i < ControlList.size(); i++ ) for( i = 0; i < ControlList.size(); i++ )
ControlList[i]->Draw( x, y, w, h, Buffer ); ControlList[i]->Draw( x, y, w, h, Buffer );
// Copy buffer in Image // Copy buffer in Image
Image->CopyFrom( x, y, w, h, Buffer, 0, 0, SRC_COPY ); 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 ) ...@@ -317,7 +317,6 @@ void SkinWindow::Refresh( int x, int y, int w, int h )
// And copy buffer to window // And copy buffer to window
RefreshFromImage( x, y, w, h ); RefreshFromImage( x, y, w, h );
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SkinWindow::RefreshAll() void SkinWindow::RefreshAll()
...@@ -327,16 +326,17 @@ void SkinWindow::RefreshAll() ...@@ -327,16 +326,17 @@ void SkinWindow::RefreshAll()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void SkinWindow::MouseDown( int x, int y, int button ) void SkinWindow::MouseDown( int x, int y, int button )
{ {
// Checking event in controls // 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 ) void SkinWindow::MouseMove( int x, int y, int button )
...@@ -350,20 +350,22 @@ 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 // 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 // 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() ) ControlList[i]->SendNewHelpText();
{ break;
break;
}
} }
} }
...@@ -375,10 +377,13 @@ void SkinWindow::MouseMove( int x, int y, int button ) ...@@ -375,10 +377,13 @@ void SkinWindow::MouseMove( int x, int y, int button )
} }
// Checking for change in Tool Tip // 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; break;
}
} }
// If no change, delete tooltip text // If no change, delete tooltip text
...@@ -403,11 +408,14 @@ void SkinWindow::MouseUp( int x, int y, int button ) ...@@ -403,11 +408,14 @@ void SkinWindow::MouseUp( int x, int y, int button )
} }
// Checking event in controls // 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 ) ...@@ -417,21 +425,26 @@ void SkinWindow::MouseDblClick( int x, int y, int button )
int i; int i;
// Checking event in controls // 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 ) ) if( ControlList[i]->IsVisible() &&
return; 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 ) void SkinWindow::MouseScroll( int x, int y, int direction )
{ {
// Checking event in controls // 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() ...@@ -462,10 +475,10 @@ void SkinWindow::ReSize()
{ {
#define min(a,b) ((a)<(b))?(a):(b) #define min(a,b) ((a)<(b))?(a):(b)
#define max(a,b) ((a)>(b))?(a):(b) #define max(a,b) ((a)>(b))?(a):(b)
w = max( w, ControlList[i]->Left + ControlList[i]->Width ); w = max( w, ControlList[i]->GetLeft() + ControlList[i]->GetWidth() );
h = max( h, ControlList[i]->Top + ControlList[i]->Height ); h = max( h, ControlList[i]->GetTop() + ControlList[i]->GetHeight() );
MinX = min( MinX, ControlList[i]->Left ); MinX = min( MinX, ControlList[i]->GetLeft() );
MinY = min( MinY, ControlList[i]->Top ); MinY = min( MinY, ControlList[i]->GetTop() );
#undef max #undef max
#undef min #undef min
} }
......
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