Commit 1f7eddac authored by JP Dinger's avatar JP Dinger

Skins2: Mostly cosmetics, some C++ style casting, factor out a scroll() in...

Skins2: Mostly cosmetics, some C++ style casting, factor out a scroll() in anticipation of figuring out where it belongs.
parent 28956620
...@@ -37,10 +37,9 @@ CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap, ...@@ -37,10 +37,9 @@ CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap ), CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap ),
m_rCommand( rCommand ), m_resizeMethod( resizeMethod ) m_rCommand( rCommand ), m_resizeMethod( resizeMethod )
{ {
OSFactory *pOsFactory = OSFactory::instance( pIntf );
// Create an initial unscaled image in the buffer // Create an initial unscaled image in the buffer
m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(), m_pImage = OSFactory::instance( pIntf )->createOSGraphics(
rBitmap.getHeight() ); rBitmap.getWidth(), rBitmap.getHeight() );
m_pImage->drawBitmap( m_rBitmap ); m_pImage->drawBitmap( m_rBitmap );
} }
...@@ -56,13 +55,11 @@ void CtrlImage::handleEvent( EvtGeneric &rEvent ) ...@@ -56,13 +55,11 @@ void CtrlImage::handleEvent( EvtGeneric &rEvent )
// No FSM for this simple transition // No FSM for this simple transition
if( rEvent.getAsString() == "mouse:right:up:none" ) if( rEvent.getAsString() == "mouse:right:up:none" )
{ {
CmdDlgShowPopupMenu cmd( getIntf() ); CmdDlgShowPopupMenu( getIntf() ).execute();
cmd.execute();
} }
else if( rEvent.getAsString() == "mouse:left:up:none" ) else if( rEvent.getAsString() == "mouse:left:up:none" )
{ {
CmdDlgHidePopupMenu cmd( getIntf() ); CmdDlgHidePopupMenu( getIntf() ).execute();
cmd.execute();
} }
else if( rEvent.getAsString() == "mouse:left:dblclick:none" ) else if( rEvent.getAsString() == "mouse:left:dblclick:none" )
{ {
...@@ -79,13 +76,10 @@ bool CtrlImage::mouseOver( int x, int y ) const ...@@ -79,13 +76,10 @@ bool CtrlImage::mouseOver( int x, int y ) const
{ {
// In mosaic mode, convert the coordinates to make them fit to the // In mosaic mode, convert the coordinates to make them fit to the
// size of the original image // size of the original image
return m_pImage->hit( x % m_pImage->getWidth(), x %= m_pImage->getWidth();
y % m_pImage->getHeight() ); y %= m_pImage->getHeight();
}
else
{
return m_pImage->hit( x, y );
} }
return m_pImage->hit( x, y );
} }
......
...@@ -44,9 +44,8 @@ CtrlRadialSlider::CtrlRadialSlider( intf_thread_t *pIntf, ...@@ -44,9 +44,8 @@ CtrlRadialSlider::CtrlRadialSlider( intf_thread_t *pIntf,
m_cmdMove( this ) m_cmdMove( this )
{ {
// Build the images of the sequence // Build the images of the sequence
OSFactory *pOsFactory = OSFactory::instance( getIntf() ); m_pImgSeq = OSFactory::instance( getIntf() )->createOSGraphics(
m_pImgSeq = pOsFactory->createOSGraphics( rBmpSeq.getWidth(), rBmpSeq.getWidth(), rBmpSeq.getHeight() );
rBmpSeq.getHeight() );
m_pImgSeq->drawBitmap( rBmpSeq, 0, 0 ); m_pImgSeq->drawBitmap( rBmpSeq, 0, 0 );
m_width = rBmpSeq.getWidth(); m_width = rBmpSeq.getWidth();
...@@ -125,7 +124,7 @@ void CtrlRadialSlider::CmdDownUp::execute() ...@@ -125,7 +124,7 @@ void CtrlRadialSlider::CmdDownUp::execute()
void CtrlRadialSlider::CmdMove::execute() void CtrlRadialSlider::CmdMove::execute()
{ {
EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt; EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
// Change the position of the cursor, in blocking mode // Change the position of the cursor, in blocking mode
m_pParent->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), true ); m_pParent->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), true );
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, write to the Free Software * with this program; if not, write to the Free Software Foundation, Inc.,
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include "ctrl_resize.hpp" #include "ctrl_resize.hpp"
...@@ -113,15 +113,16 @@ void CtrlResize::handleEvent( EvtGeneric &rEvent ) ...@@ -113,15 +113,16 @@ void CtrlResize::handleEvent( EvtGeneric &rEvent )
void CtrlResize::changeCursor( WindowManager::Direction_t direction ) const void CtrlResize::changeCursor( WindowManager::Direction_t direction ) const
{ {
OSFactory *pOsFactory = OSFactory::instance( getIntf() ); OSFactory::CursorType_t cursor;
if( direction == WindowManager::kResizeSE ) switch( direction )
pOsFactory->changeCursor( OSFactory::kResizeNWSE ); {
else if( direction == WindowManager::kResizeS ) default:
pOsFactory->changeCursor( OSFactory::kResizeNS ); case WindowManager::kNone: cursor = OSFactory::kDefaultArrow; break;
else if( direction == WindowManager::kResizeE ) case WindowManager::kResizeSE: cursor = OSFactory::kResizeNWSE; break;
pOsFactory->changeCursor( OSFactory::kResizeWE ); case WindowManager::kResizeS: cursor = OSFactory::kResizeNS; break;
else if( direction == WindowManager::kNone ) case WindowManager::kResizeE: cursor = OSFactory::kResizeWE; break;
pOsFactory->changeCursor( OSFactory::kDefaultArrow ); }
OSFactory::instance( getIntf() )->changeCursor( cursor );
} }
...@@ -145,7 +146,7 @@ void CtrlResize::CmdStillStill::execute() ...@@ -145,7 +146,7 @@ void CtrlResize::CmdStillStill::execute()
void CtrlResize::CmdStillResize::execute() void CtrlResize::CmdStillResize::execute()
{ {
EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt; EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
// Set the cursor // Set the cursor
m_pParent->changeCursor( m_pParent->m_direction ); m_pParent->changeCursor( m_pParent->m_direction );
...@@ -176,9 +177,8 @@ void CtrlResize::CmdResizeStill::execute() ...@@ -176,9 +177,8 @@ void CtrlResize::CmdResizeStill::execute()
void CtrlResize::CmdResizeResize::execute() void CtrlResize::CmdResizeResize::execute()
{ {
EvtMotion *pEvtMotion = (EvtMotion*)m_pParent->m_pEvt; EvtMotion *pEvtMotion = static_cast<EvtMotion*>(m_pParent->m_pEvt);
// Set the cursor
m_pParent->changeCursor( m_pParent->m_direction ); m_pParent->changeCursor( m_pParent->m_direction );
int newWidth = m_pParent->m_width; int newWidth = m_pParent->m_width;
...@@ -194,6 +194,5 @@ void CtrlResize::CmdResizeResize::execute() ...@@ -194,6 +194,5 @@ void CtrlResize::CmdResizeResize::execute()
m_pParent->m_rLayout, m_pParent->m_rLayout,
newWidth, newHeight ); newWidth, newHeight );
// Push the command in the asynchronous command queue // Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( getIntf() ); AsyncQueue::instance( getIntf() )->push( CmdGenericPtr( pCmd ) );
pQueue->push( CmdGenericPtr( pCmd ) );
} }
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, write to the Free Software * with this program; if not, write to the Free Software Foundation, Inc.,
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include "ctrl_slider.hpp" #include "ctrl_slider.hpp"
...@@ -38,6 +38,11 @@ ...@@ -38,6 +38,11 @@
#define RANGE 40 #define RANGE 40
#define SCROLL_STEP 0.05f #define SCROLL_STEP 0.05f
static inline float scroll( bool up, float pct )
{
return pct + (up? SCROLL_STEP : -SCROLL_STEP);
}
CtrlSliderCursor::CtrlSliderCursor( intf_thread_t *pIntf, CtrlSliderCursor::CtrlSliderCursor( intf_thread_t *pIntf,
const GenericBitmap &rBmpUp, const GenericBitmap &rBmpUp,
...@@ -170,7 +175,7 @@ void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable, ...@@ -170,7 +175,7 @@ void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable,
void CtrlSliderCursor::CmdOverDown::execute() void CtrlSliderCursor::CmdOverDown::execute()
{ {
EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt; EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
// Compute the resize factors // Compute the resize factors
float factorX, factorY; float factorX, factorY;
...@@ -220,7 +225,7 @@ void CtrlSliderCursor::CmdOverUp::execute() ...@@ -220,7 +225,7 @@ void CtrlSliderCursor::CmdOverUp::execute()
void CtrlSliderCursor::CmdMove::execute() void CtrlSliderCursor::CmdMove::execute()
{ {
EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt; EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
// Get the position of the control // Get the position of the control
const Position *pPos = m_pParent->getPosition(); const Position *pPos = m_pParent->getPosition();
...@@ -251,21 +256,10 @@ void CtrlSliderCursor::CmdMove::execute() ...@@ -251,21 +256,10 @@ void CtrlSliderCursor::CmdMove::execute()
void CtrlSliderCursor::CmdScroll::execute() void CtrlSliderCursor::CmdScroll::execute()
{ {
EvtScroll *pEvtScroll = (EvtScroll*)m_pParent->m_pEvt; // XXX Two of these in this file, figure out where it really belongs.
int dir = static_cast<EvtScroll*>(m_pParent->m_pEvt)->getDirection();
int direction = pEvtScroll->getDirection(); m_pParent->m_rVariable.set( scroll( EvtScroll::kUp == dir,
m_pParent->m_rVariable.get() ) );
float percentage = m_pParent->m_rVariable.get();
if( direction == EvtScroll::kUp )
{
percentage += SCROLL_STEP;
}
else
{
percentage -= SCROLL_STEP;
}
m_pParent->m_rVariable.set( percentage );
} }
...@@ -280,19 +274,17 @@ void CtrlSliderCursor::getResizeFactors( float &rFactorX, ...@@ -280,19 +274,17 @@ void CtrlSliderCursor::getResizeFactors( float &rFactorX,
// Compute the resize factors // Compute the resize factors
if( m_width > 0 ) if( m_width > 0 )
{
rFactorX = (float)pPos->getWidth() / (float)m_width; rFactorX = (float)pPos->getWidth() / (float)m_width;
}
if( m_height > 0 ) if( m_height > 0 )
{
rFactorY = (float)pPos->getHeight() / (float)m_height; rFactorY = (float)pPos->getHeight() / (float)m_height;
}
} }
void CtrlSliderCursor::refreshLayout() void CtrlSliderCursor::refreshLayout()
{ {
if( m_pImg ) if( !m_pImg )
notifyLayout();
else
{ {
// Compute the resize factors // Compute the resize factors
float factorX, factorY; float factorX, factorY;
...@@ -303,8 +295,6 @@ void CtrlSliderCursor::refreshLayout() ...@@ -303,8 +295,6 @@ void CtrlSliderCursor::refreshLayout()
- m_pImg->getWidth() / 2, - m_pImg->getWidth() / 2,
- m_pImg->getHeight() / 2 ); - m_pImg->getHeight() / 2 );
} }
else
notifyLayout();
} }
...@@ -359,28 +349,25 @@ bool CtrlSliderBg::mouseOver( int x, int y ) const ...@@ -359,28 +349,25 @@ bool CtrlSliderBg::mouseOver( int x, int y ) const
void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest ) void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest )
{ {
if( m_pImgSeq ) if( !m_pImgSeq || m_bgWidth <=0 || m_bgHeight <= 0 )
{ return;
if( m_bgWidth > 0 && m_bgHeight > 0 )
{ // Compute the resize factors
// Compute the resize factors float factorX, factorY;
float factorX, factorY; getResizeFactors( factorX, factorY );
getResizeFactors( factorX, factorY );
// Rescale the image with the actual size of the control
// Rescale the image with the actual size of the control ScaledBitmap bmp( getIntf(), *m_pImgSeq,
ScaledBitmap bmp( getIntf(), *m_pImgSeq, m_bgWidth * m_nbHoriz - (int)(m_padHoriz * factorX),
m_bgWidth * m_nbHoriz - (int)(m_padHoriz * factorX), m_bgHeight * m_nbVert - (int)(m_padVert * factorY) );
m_bgHeight * m_nbVert - (int)(m_padVert * factorY) );
// Locate the right image in the background bitmap
// Locate the right image in the background bitmap int x = m_bgWidth * ( m_position % m_nbHoriz );
int x = m_bgWidth * ( m_position % m_nbHoriz ); int y = m_bgHeight * ( m_position / m_nbHoriz );
int y = m_bgHeight * ( m_position / m_nbHoriz ); // Draw the background image
// Draw the background image rImage.drawBitmap( bmp, x, y, xDest, yDest,
rImage.drawBitmap( bmp, x, y, xDest, yDest, m_bgWidth - (int)(m_padHoriz * factorX),
m_bgWidth - (int)(m_padHoriz * factorX), m_bgHeight - (int)(m_padVert * factorY) );
m_bgHeight - (int)(m_padVert * factorY) );
}
}
} }
...@@ -416,19 +403,9 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent ) ...@@ -416,19 +403,9 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
} }
else if( rEvent.getAsString().find( "scroll" ) != string::npos ) else if( rEvent.getAsString().find( "scroll" ) != string::npos )
{ {
int direction = ((EvtScroll&)rEvent).getDirection(); // XXX Two of these in this file, figure out where it really belongs.
int dir = static_cast<EvtScroll*>(&rEvent)->getDirection();
float percentage = m_rVariable.get(); m_rVariable.set( scroll( EvtScroll::kUp == dir, m_rVariable.get() ) );
if( direction == EvtScroll::kUp )
{
percentage += SCROLL_STEP;
}
else
{
percentage -= SCROLL_STEP;
}
m_rVariable.set( percentage );
} }
} }
...@@ -474,12 +451,8 @@ void CtrlSliderBg::getResizeFactors( float &rFactorX, float &rFactorY ) const ...@@ -474,12 +451,8 @@ void CtrlSliderBg::getResizeFactors( float &rFactorX, float &rFactorY ) const
// Compute the resize factors // Compute the resize factors
if( m_width > 0 ) if( m_width > 0 )
{
rFactorX = (float)pPos->getWidth() / (float)m_width; rFactorX = (float)pPos->getWidth() / (float)m_width;
}
if( m_height > 0 ) if( m_height > 0 )
{
rFactorY = (float)pPos->getHeight() / (float)m_height; rFactorY = (float)pPos->getHeight() / (float)m_height;
}
} }
...@@ -574,7 +574,10 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -574,7 +574,10 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
else if( rEvent.getAsString().find( "scroll" ) != string::npos ) else if( rEvent.getAsString().find( "scroll" ) != string::npos )
{ {
int direction = ((EvtScroll&)rEvent).getDirection(); // XXX ctrl_slider.cpp has two more (but slightly different)
// XXX implementations of `scroll'. Figure out where it belongs.
int direction = static_cast<EvtScroll&>(rEvent).getDirection();
double percentage = m_rTree.getPositionVar().get(); double percentage = m_rTree.getPositionVar().get();
double step = 2.0 / (double)( m_flat ? m_rTree.countLeafs() double step = 2.0 / (double)( m_flat ? m_rTree.countLeafs()
...@@ -622,17 +625,14 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent ) ...@@ -622,17 +625,14 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
bool CtrlTree::mouseOver( int x, int y ) const bool CtrlTree::mouseOver( int x, int y ) const
{ {
const Position *pPos = getPosition(); const Position *pPos = getPosition();
return ( pPos return !pPos ? false :
? x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight() x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight();
: false);
} }
void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest ) void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest )
{ {
if( m_pImage ) if( m_pImage )
{
rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest ); rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
}
} }
bool CtrlTree::ensureVisible( VarTree::Iterator item ) bool CtrlTree::ensureVisible( VarTree::Iterator item )
...@@ -776,7 +776,9 @@ void CtrlTree::makeImage() ...@@ -776,7 +776,9 @@ void CtrlTree::makeImage()
for( int yPos = 0; yPos < height; yPos += i_itemHeight ) for( int yPos = 0; yPos < height; yPos += i_itemHeight )
{ {
int rectHeight = __MIN( i_itemHeight, height - yPos ); int rectHeight = __MIN( i_itemHeight, height - yPos );
if( it != m_rTree.end() ) if( it == m_rTree.end() )
m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor );
else
{ {
uint32_t color = ( it->m_selected ? m_selColor : bgColor ); uint32_t color = ( it->m_selected ? m_selColor : bgColor );
m_pImage->fillRect( 0, yPos, width, rectHeight, color ); m_pImage->fillRect( 0, yPos, width, rectHeight, color );
...@@ -786,10 +788,6 @@ void CtrlTree::makeImage() ...@@ -786,10 +788,6 @@ void CtrlTree::makeImage()
: m_rTree.getNextVisibleItem( it ); : m_rTree.getNextVisibleItem( it );
} while( it != m_rTree.end() && it->m_deleted ); } while( it != m_rTree.end() && it->m_deleted );
} }
else
{
m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor );
}
bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 ); bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 );
} }
} }
......
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