1 /*****************************************************************************
2 * button.cpp: Button control
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: button.cpp,v 1.9 2003/04/16 21:40:07 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 ------------------------------------------------------------------
31 #include "../src/bitmap.h"
32 #include "../src/banks.h"
35 #include "../src/event.h"
36 #include "../src/theme.h"
37 #include "../src/window.h"
38 #include "../src/skin_common.h"
40 //---------------------------------------------------------------------------
42 //---------------------------------------------------------------------------
43 ControlButton::ControlButton(
47 string Up, string Down, string Disabled,
48 string onclick, string onmouseover, string onmouseout,
49 string tooltiptext, string help,
50 Window *Parent ) : GenericControl( id, visible, help, Parent )
55 State = 1; // 1 = up - 0 = down
61 this->Disabled = Disabled;
64 ClickActionName = onclick;
65 MouseOverActionName = onmouseover;
66 MouseOutActionName = onmouseout;
69 ToolTipText = tooltiptext;
71 //---------------------------------------------------------------------------
72 ControlButton::~ControlButton()
75 //---------------------------------------------------------------------------
76 void ControlButton::Init()
79 Img = new (Bitmap*)[3];
80 Img[0] = p_intf->p_sys->p_theme->BmpBank->Get( Up );
81 Img[1] = p_intf->p_sys->p_theme->BmpBank->Get( Down );
82 if( Disabled == "none" )
83 Img[2] = p_intf->p_sys->p_theme->BmpBank->Get( Up );
85 Img[2] = p_intf->p_sys->p_theme->BmpBank->Get( Disabled );
87 // Get size of control
88 Img[0]->GetSize( Width, Height );
91 ClickAction = new Action( p_intf, ClickActionName );
92 MouseOverAction = new Action( p_intf, MouseOverActionName );
93 MouseOutAction = new Action( p_intf, MouseOutActionName );
95 //---------------------------------------------------------------------------
96 bool ControlButton::ProcessEvent( Event *evt )
98 switch( evt->GetMessage() )
101 Enable( (Event*)evt->GetParam1(), (bool)evt->GetParam2() );
106 //---------------------------------------------------------------------------
107 void ControlButton::MoveRelative( int xOff, int yOff )
112 //---------------------------------------------------------------------------
113 void ControlButton::Draw( int x, int y, int w, int h, Graphics *dest )
119 if( GetIntersectRgn( x,y,w,h,Left,Top,Width,Height, xI, yI, wI, hI ) )
121 // Button is in down state
122 if( State == 0 && Enabled )
123 Img[1]->DrawBitmap( xI-Left, yI-Top, wI, hI, xI-x, yI-y, dest );
125 // Button is in up state
126 if( State == 1 && Enabled )
127 Img[0]->DrawBitmap( xI-Left, yI-Top, wI, hI, xI-x, yI-y, dest );
129 // Button is disabled
131 Img[2]->DrawBitmap( xI-Left, yI-Top, wI, hI, xI-x, yI-y, dest );
134 //---------------------------------------------------------------------------
135 bool ControlButton::MouseUp( int x, int y, int button )
137 // If hit in the button
138 if( Img[1]->Hit( x - Left, y - Top ) )
143 if( button == 1 && Selected )
147 ClickAction->SendEvent();
148 ParentWindow->Refresh( Left, Top, Width, Height );
158 //---------------------------------------------------------------------------
159 bool ControlButton::MouseDown( int x, int y, int button )
161 if( Img[0]->Hit( x - Left, y - Top ) )
170 ParentWindow->Refresh( Left, Top, Width, Height );
177 //---------------------------------------------------------------------------
178 bool ControlButton::MouseMove( int x, int y, int button )
184 if( MouseOver( x, y ) && !CursorIn )
186 if( button == 1 && Selected )
189 ParentWindow->Refresh( Left, Top, Width, Height );
192 if( MouseOverActionName != "none" )
194 MouseOverAction->SendEvent();
200 else if( !MouseOver( x, y ) & CursorIn )
203 if( button == 1 && Selected )
206 ParentWindow->Refresh( Left, Top, Width, Height );
209 if( MouseOutActionName != "none" )
211 MouseOutAction->SendEvent();
220 //---------------------------------------------------------------------------
221 bool ControlButton::MouseOver( int x, int y )
223 if( Img[1 - State]->Hit( x - Left, y - Top ) )
232 //---------------------------------------------------------------------------
233 bool ControlButton::ToolTipTest( int x, int y )
235 if( MouseOver( x, y ) && Enabled )
237 ParentWindow->ChangeToolTipText( ToolTipText );
242 //---------------------------------------------------------------------------
243 void ControlButton::Enable( Event *event, bool enabled )
245 if( !ClickAction->MatchEvent( event, ACTION_MATCH_ONE ) )
248 if( enabled != Enabled )
252 // If cursor is in, send mouse out event
253 if( !Enabled && CursorIn )
255 if( MouseOutActionName != "none" )
256 MouseOutAction->SendEvent();
260 ParentWindow->Refresh( Left, Top, Width, Height );
263 //---------------------------------------------------------------------------