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 @@
* 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 Teulire <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;
......
......@@ -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 Teulire <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()
{
}
......
......@@ -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; }
};
//---------------------------------------------------------------------------
......
......@@ -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 Teulire <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 )
......
......@@ -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 Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr>
......
......@@ -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 Teulire <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];
}
}
......
......@@ -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 Teulire <ipkiss@via.ecp.fr>
* Emmanuel Puig <karibu@via.ecp.fr>
......@@ -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,22 +350,24 @@ 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]->SendNewHelpText() )
if( ControlList[i]->IsVisible() && ControlList[i]->MouseOver( x, y ) )
{
ControlList[i]->SendNewHelpText();
break;
}
}
}
// If help text not found, change it to ""
if( i == -1 )
......@@ -375,11 +377,14 @@ 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]->IsVisible() &&
ControlList[i]->ToolTipTest( x, y ) )
{
if( ControlList[i]->ToolTipTest( x, y ) )
break;
}
}
// If no change, delete tooltip text
if( i == -1 )
......@@ -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
}
......
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