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,
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
m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(),
rBitmap.getHeight() );
m_pImage = OSFactory::instance( pIntf )->createOSGraphics(
rBitmap.getWidth(), rBitmap.getHeight() );
m_pImage->drawBitmap( m_rBitmap );
}
......@@ -56,13 +55,11 @@ void CtrlImage::handleEvent( EvtGeneric &rEvent )
// No FSM for this simple transition
if( rEvent.getAsString() == "mouse:right:up:none" )
{
CmdDlgShowPopupMenu cmd( getIntf() );
cmd.execute();
CmdDlgShowPopupMenu( getIntf() ).execute();
}
else if( rEvent.getAsString() == "mouse:left:up:none" )
{
CmdDlgHidePopupMenu cmd( getIntf() );
cmd.execute();
CmdDlgHidePopupMenu( getIntf() ).execute();
}
else if( rEvent.getAsString() == "mouse:left:dblclick:none" )
{
......@@ -79,13 +76,10 @@ bool CtrlImage::mouseOver( int x, int y ) const
{
// 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() );
x %= m_pImage->getWidth();
y %= m_pImage->getHeight();
}
else
{
return m_pImage->hit( x, y );
}
}
......
......@@ -44,9 +44,8 @@ CtrlRadialSlider::CtrlRadialSlider( intf_thread_t *pIntf,
m_cmdMove( this )
{
// Build the images of the sequence
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
m_pImgSeq = pOsFactory->createOSGraphics( rBmpSeq.getWidth(),
rBmpSeq.getHeight() );
m_pImgSeq = OSFactory::instance( getIntf() )->createOSGraphics(
rBmpSeq.getWidth(), rBmpSeq.getHeight() );
m_pImgSeq->drawBitmap( rBmpSeq, 0, 0 );
m_width = rBmpSeq.getWidth();
......@@ -125,7 +124,7 @@ void CtrlRadialSlider::CmdDownUp::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
m_pParent->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), true );
......
......@@ -17,9 +17,9 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "ctrl_resize.hpp"
......@@ -113,15 +113,16 @@ void CtrlResize::handleEvent( EvtGeneric &rEvent )
void CtrlResize::changeCursor( WindowManager::Direction_t direction ) const
{
OSFactory *pOsFactory = OSFactory::instance( getIntf() );
if( direction == WindowManager::kResizeSE )
pOsFactory->changeCursor( OSFactory::kResizeNWSE );
else if( direction == WindowManager::kResizeS )
pOsFactory->changeCursor( OSFactory::kResizeNS );
else if( direction == WindowManager::kResizeE )
pOsFactory->changeCursor( OSFactory::kResizeWE );
else if( direction == WindowManager::kNone )
pOsFactory->changeCursor( OSFactory::kDefaultArrow );
OSFactory::CursorType_t cursor;
switch( direction )
{
default:
case WindowManager::kNone: cursor = OSFactory::kDefaultArrow; break;
case WindowManager::kResizeSE: cursor = OSFactory::kResizeNWSE; break;
case WindowManager::kResizeS: cursor = OSFactory::kResizeNS; break;
case WindowManager::kResizeE: cursor = OSFactory::kResizeWE; break;
}
OSFactory::instance( getIntf() )->changeCursor( cursor );
}
......@@ -145,7 +146,7 @@ void CtrlResize::CmdStillStill::execute()
void CtrlResize::CmdStillResize::execute()
{
EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
// Set the cursor
m_pParent->changeCursor( m_pParent->m_direction );
......@@ -176,9 +177,8 @@ void CtrlResize::CmdResizeStill::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 );
int newWidth = m_pParent->m_width;
......@@ -194,6 +194,5 @@ void CtrlResize::CmdResizeResize::execute()
m_pParent->m_rLayout,
newWidth, newHeight );
// Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
pQueue->push( CmdGenericPtr( pCmd ) );
AsyncQueue::instance( getIntf() )->push( CmdGenericPtr( pCmd ) );
}
......@@ -17,9 +17,9 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "ctrl_slider.hpp"
......@@ -38,6 +38,11 @@
#define RANGE 40
#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,
const GenericBitmap &rBmpUp,
......@@ -170,7 +175,7 @@ void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable,
void CtrlSliderCursor::CmdOverDown::execute()
{
EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
// Compute the resize factors
float factorX, factorY;
......@@ -220,7 +225,7 @@ void CtrlSliderCursor::CmdOverUp::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
const Position *pPos = m_pParent->getPosition();
......@@ -251,21 +256,10 @@ void CtrlSliderCursor::CmdMove::execute()
void CtrlSliderCursor::CmdScroll::execute()
{
EvtScroll *pEvtScroll = (EvtScroll*)m_pParent->m_pEvt;
int direction = pEvtScroll->getDirection();
float percentage = m_pParent->m_rVariable.get();
if( direction == EvtScroll::kUp )
{
percentage += SCROLL_STEP;
}
else
{
percentage -= SCROLL_STEP;
}
m_pParent->m_rVariable.set( percentage );
// XXX Two of these in this file, figure out where it really belongs.
int dir = static_cast<EvtScroll*>(m_pParent->m_pEvt)->getDirection();
m_pParent->m_rVariable.set( scroll( EvtScroll::kUp == dir,
m_pParent->m_rVariable.get() ) );
}
......@@ -280,19 +274,17 @@ void CtrlSliderCursor::getResizeFactors( float &rFactorX,
// Compute the resize factors
if( m_width > 0 )
{
rFactorX = (float)pPos->getWidth() / (float)m_width;
}
if( m_height > 0 )
{
rFactorY = (float)pPos->getHeight() / (float)m_height;
}
}
void CtrlSliderCursor::refreshLayout()
{
if( m_pImg )
if( !m_pImg )
notifyLayout();
else
{
// Compute the resize factors
float factorX, factorY;
......@@ -303,8 +295,6 @@ void CtrlSliderCursor::refreshLayout()
- m_pImg->getWidth() / 2,
- m_pImg->getHeight() / 2 );
}
else
notifyLayout();
}
......@@ -359,10 +349,9 @@ bool CtrlSliderBg::mouseOver( int x, int y ) const
void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest )
{
if( m_pImgSeq )
{
if( m_bgWidth > 0 && m_bgHeight > 0 )
{
if( !m_pImgSeq || m_bgWidth <=0 || m_bgHeight <= 0 )
return;
// Compute the resize factors
float factorX, factorY;
getResizeFactors( factorX, factorY );
......@@ -379,8 +368,6 @@ void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest )
rImage.drawBitmap( bmp, x, y, xDest, yDest,
m_bgWidth - (int)(m_padHoriz * factorX),
m_bgHeight - (int)(m_padVert * factorY) );
}
}
}
......@@ -416,19 +403,9 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
}
else if( rEvent.getAsString().find( "scroll" ) != string::npos )
{
int direction = ((EvtScroll&)rEvent).getDirection();
float percentage = m_rVariable.get();
if( direction == EvtScroll::kUp )
{
percentage += SCROLL_STEP;
}
else
{
percentage -= SCROLL_STEP;
}
m_rVariable.set( percentage );
// XXX Two of these in this file, figure out where it really belongs.
int dir = static_cast<EvtScroll*>(&rEvent)->getDirection();
m_rVariable.set( scroll( EvtScroll::kUp == dir, m_rVariable.get() ) );
}
}
......@@ -474,12 +451,8 @@ void CtrlSliderBg::getResizeFactors( float &rFactorX, float &rFactorY ) const
// Compute the resize factors
if( m_width > 0 )
{
rFactorX = (float)pPos->getWidth() / (float)m_width;
}
if( m_height > 0 )
{
rFactorY = (float)pPos->getHeight() / (float)m_height;
}
}
......@@ -574,7 +574,10 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
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 step = 2.0 / (double)( m_flat ? m_rTree.countLeafs()
......@@ -622,17 +625,14 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
bool CtrlTree::mouseOver( int x, int y ) const
{
const Position *pPos = getPosition();
return ( pPos
? x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight()
: false);
return !pPos ? false :
x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight();
}
void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest )
{
if( m_pImage )
{
rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
}
}
bool CtrlTree::ensureVisible( VarTree::Iterator item )
......@@ -776,7 +776,9 @@ void CtrlTree::makeImage()
for( int yPos = 0; yPos < height; yPos += i_itemHeight )
{
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 );
m_pImage->fillRect( 0, yPos, width, rectHeight, color );
......@@ -786,10 +788,6 @@ void CtrlTree::makeImage()
: m_rTree.getNextVisibleItem( it );
} 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 );
}
}
......
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