1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@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, USA.
23 *****************************************************************************/
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"
34 CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
35 resize_t resizeMethod, const UString &rHelp,
37 CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap ),
38 m_resizeMethod( resizeMethod )
40 OSFactory *pOsFactory = OSFactory::instance( pIntf );
41 // Create an initial unscaled image in the buffer
42 m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(),
43 rBitmap.getHeight() );
44 m_pImage->drawBitmap( m_rBitmap );
48 CtrlImage::~CtrlImage()
50 SKINS_DELETE( m_pImage );
54 void CtrlImage::handleEvent( EvtGeneric &rEvent )
56 // No FSM for this simple transition
57 if( rEvent.getAsString() == "mouse:right:up:none" )
59 CmdDlgShowPopupMenu cmd( getIntf() );
62 else if( rEvent.getAsString() == "mouse:left:up:none" )
64 CmdDlgHidePopupMenu cmd( getIntf() );
71 bool CtrlImage::mouseOver( int x, int y ) const
73 if( m_resizeMethod == kMosaic &&
74 x >= 0 && x < getPosition()->getWidth() &&
75 y >= 0 && y < getPosition()->getHeight() )
77 // In mosaic mode, convert the coordinates to make them fit to the
78 // size of the original image
79 return m_pImage->hit( x % m_pImage->getWidth(),
80 y % m_pImage->getHeight() );
84 return m_pImage->hit( x, y );
89 void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest )
91 const Position *pPos = getPosition();
94 int width = pPos->getWidth();
95 int height = pPos->getHeight();
97 if( m_resizeMethod == kScale )
100 if( width != m_pImage->getWidth() ||
101 height != m_pImage->getHeight() )
103 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
104 // Rescale the image with the actual size of the control
105 ScaledBitmap bmp( getIntf(), m_rBitmap, width, height );
106 SKINS_DELETE( m_pImage );
107 m_pImage = pOsFactory->createOSGraphics( width, height );
108 m_pImage->drawBitmap( bmp, 0, 0 );
110 rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
117 int curWidth = __MIN( width, m_pImage->getWidth() );
118 height = pPos->getHeight();
119 int curYDest = yDest;
122 int curHeight = __MIN( height, m_pImage->getHeight() );
123 rImage.drawGraphics( *m_pImage, 0, 0, xDest, curYDest,
124 curWidth, curHeight );
125 curYDest += curHeight;
126 height -= m_pImage->getHeight();
129 width -= m_pImage->getWidth();