1 /*****************************************************************************
2 * button.cpp: Button control
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: button.cpp,v 1.1 2003/03/18 02:21:47 ipkiss Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
30 //--- SKIN ------------------------------------------------------------------
38 #include "skin_common.h"
42 //---------------------------------------------------------------------------
44 //---------------------------------------------------------------------------
45 ControlButton::ControlButton( string id, bool visible, int x, int y, string Up,
46 string Down, string Disabled, string click, string tooltiptext, string help,
47 Window *Parent ) : GenericControl( id, visible, help, Parent )
51 State = 1; // 1 = up - 0 = down
54 ClickActionName = click;
57 this->Disabled = Disabled;
59 ToolTipText = tooltiptext;
61 //---------------------------------------------------------------------------
62 ControlButton::~ControlButton()
65 //---------------------------------------------------------------------------
66 void ControlButton::Init()
69 Img = new (Bitmap*)[3];
70 Img[0] = p_intf->p_sys->p_theme->BmpBank->Get( Up );
71 Img[1] = p_intf->p_sys->p_theme->BmpBank->Get( Down );
72 if( Disabled == "none" )
73 Img[2] = p_intf->p_sys->p_theme->BmpBank->Get( Up );
75 Img[2] = p_intf->p_sys->p_theme->BmpBank->Get( Disabled );
77 // Get size of control
78 Img[0]->GetSize( Width, Height );
81 ClickAction = new Action( p_intf, ClickActionName );
83 //---------------------------------------------------------------------------
84 bool ControlButton::ProcessEvent( Event *evt )
86 switch( evt->GetMessage() )
89 Enable( (Event*)evt->GetParam1(), (bool)evt->GetParam2() );
94 //---------------------------------------------------------------------------
95 void ControlButton::MoveRelative( int xOff, int yOff )
100 //---------------------------------------------------------------------------
101 void ControlButton::Draw( int x, int y, int w, int h, Graphics *dest )
107 if( GetIntersectRgn( x,y,w,h,Left,Top,Width,Height, xI, yI, wI, hI ) )
109 // Button is in down state
110 if( State == 0 && Enabled )
111 Img[1]->DrawBitmap( xI-Left, yI-Top, wI, hI, xI-x, yI-y, dest );
113 // Button is in up state
114 if( State == 1 && Enabled )
115 Img[0]->DrawBitmap( xI-Left, yI-Top, wI, hI, xI-x, yI-y, dest );
117 // Button is disabled
119 Img[2]->DrawBitmap( xI-Left, yI-Top, wI, hI, xI-x, yI-y, dest );
122 //---------------------------------------------------------------------------
123 bool ControlButton::MouseUp( int x, int y, int button )
128 if( Img[1]->Hit( x - Left, y - Top ) && button == 1 && Selected )
132 ClickAction->SendEvent();
133 ParentWindow->Refresh( Left, Top, Width, Height );
142 //---------------------------------------------------------------------------
143 bool ControlButton::MouseDown( int x, int y, int button )
148 if( Img[0]->Hit( x - Left, y - Top ) && button == 1 )
152 ParentWindow->Refresh( Left, Top, Width, Height );
157 //---------------------------------------------------------------------------
158 bool ControlButton::MouseMove( int x, int y, int button )
160 if( !Enabled || !Selected || !button )
163 if( MouseOver( x, y ) )
168 ParentWindow->Refresh( Left, Top, Width, Height );
176 ParentWindow->Refresh( Left, Top, Width, Height );
181 //---------------------------------------------------------------------------
182 bool ControlButton::MouseOver( int x, int y )
184 if( Img[1 - State]->Hit( x - Left, y - Top ) )
193 //---------------------------------------------------------------------------
194 bool ControlButton::ToolTipTest( int x, int y )
196 if( MouseOver( x, y ) && Enabled )
198 ParentWindow->ChangeToolTipText( ToolTipText );
203 //---------------------------------------------------------------------------
204 void ControlButton::Enable( Event *event, bool enabled )
206 if( !ClickAction->MatchEvent( event, ACTION_MATCH_ONE ) )
209 if( enabled != Enabled )
212 ParentWindow->Refresh( Left, Top, Width, Height );
215 //---------------------------------------------------------------------------