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 );
}
// 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" )
{
{
// 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 );
+ x %= m_pImage->getWidth();
+ y %= m_pImage->getHeight();
}
+ return m_pImage->hit( x, y );
}
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();
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 );
* 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"
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 );
}
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 );
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;
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 ) );
}
* 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"
#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,
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;
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();
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() ) );
}
// 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;
- m_pImg->getWidth() / 2,
- m_pImg->getHeight() / 2 );
}
- else
- notifyLayout();
}
void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest )
{
- if( m_pImgSeq )
- {
- if( m_bgWidth > 0 && m_bgHeight > 0 )
- {
- // Compute the resize factors
- float factorX, factorY;
- getResizeFactors( factorX, factorY );
-
- // Rescale the image with the actual size of the control
- ScaledBitmap bmp( getIntf(), *m_pImgSeq,
- m_bgWidth * m_nbHoriz - (int)(m_padHoriz * factorX),
- m_bgHeight * m_nbVert - (int)(m_padVert * factorY) );
-
- // 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) );
- }
- }
+ if( !m_pImgSeq || m_bgWidth <=0 || m_bgHeight <= 0 )
+ return;
+
+ // Compute the resize factors
+ float factorX, factorY;
+ getResizeFactors( factorX, factorY );
+
+ // Rescale the image with the actual size of the control
+ ScaledBitmap bmp( getIntf(), *m_pImgSeq,
+ m_bgWidth * m_nbHoriz - (int)(m_padHoriz * factorX),
+ m_bgHeight * m_nbVert - (int)(m_padVert * factorY) );
+
+ // 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) );
}
}
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() ) );
}
}
// 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;
- }
}
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()
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 )
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 );
: 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 );
}
}