00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
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
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
00088 if( width != m_pImage->getWidth() ||
00089 height != m_pImage->getHeight() )
00090 {
00091 OSFactory *pOsFactory = OSFactory::instance( getIntf() );
00092
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
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