Commit 822898c7 authored by Olivier Teulière's avatar Olivier Teulière

* skins2/controls/ctrl_image.cpp: Allow resizing to a width of 1 now that the

   bug in ScaledBitmap is fixed
 * skins2/controls/ctrl_slider.*: Support resizing of the SliderBackground control
parent 73a3acb7
...@@ -100,7 +100,7 @@ void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest ) ...@@ -100,7 +100,7 @@ void CtrlImage::draw( OSGraphics &rImage, int xDest, int yDest )
if( m_resizeMethod == kScale ) if( m_resizeMethod == kScale )
{ {
// Use scaling method // Use scaling method
if( width > 1 && height > 1 ) if( width > 0 && height > 0 )
{ {
if( width != m_pImage->getWidth() || if( width != m_pImage->getWidth() ||
height != m_pImage->getHeight() ) height != m_pImage->getHeight() )
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "../events/evt_mouse.hpp" #include "../events/evt_mouse.hpp"
#include "../events/evt_scroll.hpp" #include "../events/evt_scroll.hpp"
#include "../src/generic_bitmap.hpp" #include "../src/generic_bitmap.hpp"
#include "../src/scaled_bitmap.hpp"
#include "../src/top_window.hpp" #include "../src/top_window.hpp"
#include "../src/os_factory.hpp" #include "../src/os_factory.hpp"
#include "../src/os_graphics.hpp" #include "../src/os_graphics.hpp"
...@@ -315,18 +316,13 @@ CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf, ...@@ -315,18 +316,13 @@ CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf,
CtrlGeneric( pIntf, rHelp, pVisible ), m_pCursor( NULL ), CtrlGeneric( pIntf, rHelp, pVisible ), m_pCursor( NULL ),
m_rVariable( rVariable ), m_thickness( thickness ), m_rCurve( rCurve ), m_rVariable( rVariable ), m_thickness( thickness ), m_rCurve( rCurve ),
m_width( rCurve.getWidth() ), m_height( rCurve.getHeight() ), m_width( rCurve.getWidth() ), m_height( rCurve.getHeight() ),
m_pImgSeq( NULL ), m_nbHoriz( nbHoriz ), m_nbVert( nbVert ), m_pImgSeq( pBackground ), m_nbHoriz( nbHoriz ), m_nbVert( nbVert ),
m_padHoriz( padHoriz ), m_padVert( padVert ), m_bgWidth( 0 ), m_padHoriz( padHoriz ), m_padVert( padVert ), m_bgWidth( 0 ),
m_bgHeight( 0 ), m_position( 0 ) m_bgHeight( 0 ), m_position( 0 )
{ {
if( pBackground ) if( pBackground )
{ {
// Build the background image sequence // Build the background image sequence
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
m_pImgSeq = pOsFactory->createOSGraphics( pBackground->getWidth(),
pBackground->getHeight() );
m_pImgSeq->drawBitmap( *pBackground, 0, 0 );
m_bgWidth = (pBackground->getWidth() + m_padHoriz) / nbHoriz; m_bgWidth = (pBackground->getWidth() + m_padHoriz) / nbHoriz;
m_bgHeight = (pBackground->getHeight() + m_padVert) / nbVert; m_bgHeight = (pBackground->getHeight() + m_padVert) / nbVert;
...@@ -342,7 +338,6 @@ CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf, ...@@ -342,7 +338,6 @@ CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf,
CtrlSliderBg::~CtrlSliderBg() CtrlSliderBg::~CtrlSliderBg()
{ {
m_rVariable.delObserver( this ); m_rVariable.delObserver( this );
delete m_pImgSeq;
} }
...@@ -361,12 +356,24 @@ void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest ) ...@@ -361,12 +356,24 @@ void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest )
{ {
if( m_pImgSeq ) if( m_pImgSeq )
{ {
// Locate the right image in the background bitmap if( m_bgWidth > 0 && m_bgHeight > 0 )
int x = m_bgWidth * ( m_position % m_nbHoriz ); {
int y = m_bgHeight * ( m_position / m_nbHoriz ); // Compute the resize factors
// Draw the background image float factorX, factorY;
rImage.drawGraphics( *m_pImgSeq, x, y, xDest, yDest, getResizeFactors( factorX, factorY );
m_bgWidth - m_padHoriz, m_bgHeight - m_padVert );
// Rescale the image with the actual size of the control
ScaledBitmap bmp( getIntf(), *m_pImgSeq, m_bgWidth * m_nbHoriz,
m_bgHeight * m_nbVert );
// Locate the right image in the background bitmap
int x = m_bgWidth * ( m_position % m_nbHoriz );
int y = m_bgHeight * ( m_position / m_nbHoriz );
// Draw the background image
rImage.drawBitmap( bmp, x, y, xDest, yDest,
m_bgWidth - (int)(m_padHoriz * factorX),
m_bgHeight - (int)(m_padVert * factorY) );
}
} }
} }
...@@ -420,6 +427,24 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent ) ...@@ -420,6 +427,24 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
} }
void CtrlSliderBg::onResize()
{
if( m_pImgSeq )
{
// Compute only the new size of an elementary image.
// The actual resizing is done in the draw() method for now...
// Compute the resize factors
float factorX, factorY;
getResizeFactors( factorX, factorY );
// Size of one elementary background image (padding included)
m_bgWidth = (int)(m_pImgSeq->getWidth() * factorX / m_nbHoriz);
m_bgHeight = (int)(m_pImgSeq->getHeight() * factorY / m_nbVert);
}
}
void CtrlSliderBg::associateCursor( CtrlSliderCursor &rCursor ) void CtrlSliderBg::associateCursor( CtrlSliderCursor &rCursor )
{ {
m_pCursor = &rCursor; m_pCursor = &rCursor;
......
...@@ -128,6 +128,9 @@ class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent> ...@@ -128,6 +128,9 @@ class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
/// Handle an event /// Handle an event
virtual void handleEvent( EvtGeneric &rEvent ); virtual void handleEvent( EvtGeneric &rEvent );
/// Method called when the control is resized
virtual void onResize();
/// Get the type of control (custom RTTI) /// Get the type of control (custom RTTI)
virtual string getType() const { return "slider_bg"; } virtual string getType() const { return "slider_bg"; }
...@@ -146,7 +149,7 @@ class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent> ...@@ -146,7 +149,7 @@ class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
/// Initial size of the control /// Initial size of the control
int m_width, m_height; int m_width, m_height;
/// Background image sequence (optional) /// Background image sequence (optional)
OSGraphics *m_pImgSeq; GenericBitmap *m_pImgSeq;
/// Number of images in the background bitmap /// Number of images in the background bitmap
int m_nbHoriz, m_nbVert; int m_nbHoriz, m_nbVert;
/// Number of pixels between two images /// Number of pixels between two images
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment