]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/controls/ctrl_image.cpp
* skins2: The Image control now supports the "action2" attribute (feel free to
[vlc] / modules / gui / skins2 / controls / ctrl_image.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 984bf7e..2d5dbe3
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * ctrl_image.cpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
+ * Copyright (C) 2003 the VideoLAN team
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
 
 
 CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
+                      CmdGeneric &rCommand, resize_t resizeMethod,
                       const UString &rHelp, VarBool *pVisible ):
-    CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap )
+    CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap ),
+    m_rCommand( rCommand ), m_resizeMethod( resizeMethod )
 {
     OSFactory *pOsFactory = OSFactory::instance( pIntf );
     // Create an initial unscaled image in the buffer
@@ -62,13 +64,28 @@ void CtrlImage::handleEvent( EvtGeneric &rEvent )
         CmdDlgHidePopupMenu cmd( getIntf() );
         cmd.execute();
     }
-
+    else if( rEvent.getAsString() == "mouse:left:dblclick:none" )
+    {
+        m_rCommand.execute();
+    }
 }
 
 
 bool CtrlImage::mouseOver( int x, int y ) const
 {
-    return m_pImage->hit( x, y );
+    if( m_resizeMethod == kMosaic &&
+        x >= 0 && x < getPosition()->getWidth() &&
+        y >= 0 && y < getPosition()->getHeight() )
+    {
+        // In mosaic mode, convert the coordinates to make them fit to the
+        // size of the original image
+        return m_pImage->hit( x % m_pImage->getWidth(),
+                              y % m_pImage->getHeight() );
+    }
+    else
+    {
+        return m_pImage->hit( x, y );
+    }
 }
 
 
@@ -79,16 +96,42 @@ void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest )
     {
         int width = pPos->getWidth();
         int height = pPos->getHeight();
-        if( width != m_pImage->getWidth() || height != m_pImage->getHeight() )
+
+        if( m_resizeMethod == kScale )
+        {
+            // Use scaling method
+            if( width != m_pImage->getWidth() ||
+                height != m_pImage->getHeight() )
+            {
+                OSFactory *pOsFactory = OSFactory::instance( getIntf() );
+                // Rescale the image with the actual size of the control
+                ScaledBitmap bmp( getIntf(), m_rBitmap, width, height );
+                SKINS_DELETE( m_pImage );
+                m_pImage = pOsFactory->createOSGraphics( width, height );
+                m_pImage->drawBitmap( bmp, 0, 0 );
+            }
+            rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
+        }
+        else
         {
-            OSFactory *pOsFactory = OSFactory::instance( getIntf() );
-            // Rescale the image with the actual size of the control
-            ScaledBitmap bmp( getIntf(), m_rBitmap, width, height );
-            SKINS_DELETE( m_pImage );
-            m_pImage = pOsFactory->createOSGraphics( width, height );
-            m_pImage->drawBitmap( bmp, 0, 0 );
+            // Use mosaic method
+            while( width > 0 )
+            {
+                int curWidth = __MIN( width, m_pImage->getWidth() );
+                height = pPos->getHeight();
+                int curYDest = yDest;
+                while( height > 0 )
+                {
+                    int curHeight = __MIN( height, m_pImage->getHeight() );
+                    rImage.drawGraphics( *m_pImage, 0, 0, xDest, curYDest,
+                                         curWidth, curHeight );
+                    curYDest += curHeight;
+                    height -= m_pImage->getHeight();
+                }
+                xDest += curWidth;
+                width -= m_pImage->getWidth();
+            }
         }
-        rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
     }
 }