Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

ctrl_image.cpp

00001 /*****************************************************************************
00002  * ctrl_image.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: ctrl_image.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include "ctrl_image.hpp"
00026 #include "../commands/cmd_dialogs.hpp"
00027 #include "../events/evt_generic.hpp"
00028 #include "../src/os_factory.hpp"
00029 #include "../src/os_graphics.hpp"
00030 #include "../src/scaled_bitmap.hpp"
00031 #include "../utils/position.hpp"
00032 
00033 
00034 CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
00035                       resize_t resizeMethod, const UString &rHelp,
00036                       VarBool *pVisible ):
00037     CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap ),
00038     m_resizeMethod( resizeMethod )
00039 {
00040     OSFactory *pOsFactory = OSFactory::instance( pIntf );
00041     // Create an initial unscaled image in the buffer
00042     m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(),
00043                                              rBitmap.getHeight() );
00044     m_pImage->drawBitmap( m_rBitmap );
00045 }
00046 
00047 
00048 CtrlImage::~CtrlImage()
00049 {
00050     SKINS_DELETE( m_pImage );
00051 }
00052 
00053 
00054 void CtrlImage::handleEvent( EvtGeneric &rEvent )
00055 {
00056     // No FSM for this simple transition
00057     if( rEvent.getAsString() == "mouse:right:up:none" )
00058     {
00059         CmdDlgShowPopupMenu cmd( getIntf() );
00060         cmd.execute();
00061     }
00062     else if( rEvent.getAsString() == "mouse:left:up:none" )
00063     {
00064         CmdDlgHidePopupMenu cmd( getIntf() );
00065         cmd.execute();
00066     }
00067 
00068 }
00069 
00070 
00071 bool CtrlImage::mouseOver( int x, int y ) const
00072 {
00073     return m_pImage->hit( x, y );
00074 }
00075 
00076 
00077 void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest )
00078 {
00079     const Position *pPos = getPosition();
00080     if( pPos )
00081     {
00082         int width = pPos->getWidth();
00083         int height = pPos->getHeight();
00084 
00085         if( m_resizeMethod == kScale )
00086         {
00087             // Use scaling method
00088             if(  width != m_pImage->getWidth() ||
00089                  height != m_pImage->getHeight() )
00090             {
00091                 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
00092                 // Rescale the image with the actual size of the control
00093                 ScaledBitmap bmp( getIntf(), m_rBitmap, width, height );
00094                 SKINS_DELETE( m_pImage );
00095                 m_pImage = pOsFactory->createOSGraphics( width, height );
00096                 m_pImage->drawBitmap( bmp, 0, 0 );
00097             }
00098             rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
00099         }
00100         else
00101         {
00102             // Use mosaic method
00103             while( width > 0 )
00104             {
00105                 int curWidth = __MIN( width, m_pImage->getWidth() );
00106                 height = pPos->getHeight();
00107                 int curYDest = yDest;
00108                 while( height > 0 )
00109                 {
00110                     int curHeight = __MIN( height, m_pImage->getHeight() );
00111                     rImage.drawGraphics( *m_pImage, 0, 0, xDest, curYDest,
00112                                          curWidth, curHeight );
00113                     curYDest += curHeight;
00114                     height -= m_pImage->getHeight();
00115                 }
00116                 xDest += curWidth;
00117                 width -= m_pImage->getWidth();
00118             }
00119         }
00120     }
00121 }
00122 

Generated on Tue Dec 20 10:14:41 2005 for vlc-0.8.4a by  doxygen 1.4.2