]> git.sesse.net Git - vlc/blob - modules/gui/skins/controls/image.cpp
* fixed refresh of the playlist (and a segfault...)
[vlc] / modules / gui / skins / controls / image.cpp
1 /*****************************************************************************
2  * image.cpp: Image control
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: image.cpp,v 1.5 2003/04/16 21:40:07 ipkiss Exp $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *          Emmanuel Puig    <karibu@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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,
23  * USA.
24  *****************************************************************************/
25
26
27 //--- VLC -------------------------------------------------------------------
28 #include <vlc/intf.h>
29
30 //--- SKIN ------------------------------------------------------------------
31 #include "../src/bitmap.h"
32 #include "../src/banks.h"
33 #include "generic.h"
34 #include "image.h"
35 #include "../src/event.h"
36 #include "../src/theme.h"
37 #include "../src/window.h"
38 #include "../src/skin_common.h"
39
40
41
42 //---------------------------------------------------------------------------
43 // Control Image
44 //---------------------------------------------------------------------------
45 ControlImage::ControlImage( string id, bool visible, int x, int y, string img,
46     string event, string help, Window *Parent )
47     : GenericControl( id, visible, help, Parent )
48 {
49     Left                = x;
50     Top                 = y;
51     MouseDownActionName = event;
52     Enabled             = true;
53     Bg                  = img;
54 }
55 //---------------------------------------------------------------------------
56 ControlImage::~ControlImage()
57 {
58 }
59 //---------------------------------------------------------------------------
60 void ControlImage::Init()
61 {
62     Img    = new (Bitmap*)[1];
63     Img[0] = p_intf->p_sys->p_theme->BmpBank->Get( Bg );
64     Img[0]->GetSize( Width, Height );
65
66     // Create script
67     MouseDownAction = new Action( p_intf, MouseDownActionName );
68
69 }
70 //---------------------------------------------------------------------------
71 bool ControlImage::ProcessEvent( Event *evt  )
72 {
73
74     switch( evt->GetMessage() )
75     {
76         case CTRL_ENABLED:
77             Enable( (Event*)evt->GetParam1(), (bool)evt->GetParam2() );
78             break;
79     }
80     return false;
81 }
82 //---------------------------------------------------------------------------
83 void ControlImage::Draw( int x, int y, int w, int h, Graphics *dest )
84 {
85     if( !Visible )
86         return;
87
88     int xI, yI, wI, hI;
89     if( GetIntersectRgn(x, y, w, h, Left, Top, Width, Height, xI, yI, wI, hI ) )
90         Img[0]->DrawBitmap( xI-Left, yI-Top, wI, hI, xI-x, yI-y, dest );
91
92 }
93 //---------------------------------------------------------------------------
94 bool ControlImage::MouseDown( int x, int y, int button )
95 {
96     if( !Enabled || !Img[0]->Hit( x - Left, y - Top ) || button != 1 ||
97         !MouseDownAction->SendEvent() )
98             return false;
99
100     return true;
101 }
102 //---------------------------------------------------------------------------
103 bool ControlImage::MouseOver( int x, int y )
104 {
105     if( Img[0]->Hit( x - Left, y - Top ) )
106         return true;
107     else
108         return false;
109 }
110 //---------------------------------------------------------------------------
111 void ControlImage::Enable( Event *event, bool enabled )
112 {
113     if( !MouseDownAction->MatchEvent( event, ACTION_MATCH_ONE ) )
114         return;
115
116     if( enabled != !Enabled )
117     {
118         Enabled = enabled;
119         ParentWindow->Refresh( Left, Top, Width, Height );
120     }
121
122 }
123 //---------------------------------------------------------------------------
124
125