]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_image.cpp
Remove bogus executable permissions
[vlc] / modules / gui / skins2 / controls / ctrl_image.cpp
1 /*****************************************************************************
2  * ctrl_image.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@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, USA.
23  *****************************************************************************/
24
25 #include "ctrl_image.hpp"
26 #include "../commands/cmd_dialogs.hpp"
27 #include "../events/evt_generic.hpp"
28 #include "../src/os_factory.hpp"
29 #include "../src/os_graphics.hpp"
30 #include "../src/scaled_bitmap.hpp"
31 #include "../utils/position.hpp"
32
33
34 CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
35                       const UString &rHelp, VarBool *pVisible ):
36     CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap )
37 {
38     OSFactory *pOsFactory = OSFactory::instance( pIntf );
39     // Create an initial unscaled image in the buffer
40     m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(),
41                                              rBitmap.getHeight() );
42     m_pImage->drawBitmap( m_rBitmap );
43 }
44
45
46 CtrlImage::~CtrlImage()
47 {
48     SKINS_DELETE( m_pImage );
49 }
50
51
52 void CtrlImage::handleEvent( EvtGeneric &rEvent )
53 {
54     // No FSM for this simple transition
55     if( rEvent.getAsString() == "mouse:right:up:none" )
56     {
57         CmdDlgShowPopupMenu cmd( getIntf() );
58         cmd.execute();
59     }
60     else if( rEvent.getAsString() == "mouse:left:up:none" )
61     {
62         CmdDlgHidePopupMenu cmd( getIntf() );
63         cmd.execute();
64     }
65
66 }
67
68
69 bool CtrlImage::mouseOver( int x, int y ) const
70 {
71     return m_pImage->hit( x, y );
72 }
73
74
75 void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest )
76 {
77     const Position *pPos = getPosition();
78     if( pPos )
79     {
80         int width = pPos->getWidth();
81         int height = pPos->getHeight();
82         if( width != m_pImage->getWidth() || height != m_pImage->getHeight() )
83         {
84             OSFactory *pOsFactory = OSFactory::instance( getIntf() );
85             // Rescale the image with the actual size of the control
86             ScaledBitmap bmp( getIntf(), m_rBitmap, width, height );
87             SKINS_DELETE( m_pImage );
88             m_pImage = pOsFactory->createOSGraphics( width, height );
89             m_pImage->drawBitmap( bmp, 0, 0 );
90         }
91         rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
92     }
93 }
94