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) ); } } }
bool CtrlSliderBg::mouseOver( int x, int y ) const { // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); return (m_rCurve.getMinDist( (int)(x / factorX), (int)(y / factorY), factorX, factorY ) < m_thickness ); }
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() + m_padHoriz) * factorX / m_nbHoriz); m_bgHeight = (int)((m_pImgSeq->getHeight() + m_padVert) * factorY / m_nbVert); } }
void CtrlSliderCursor::refreshLayout() { if( m_pImg ) { // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); notifyLayout( (int)(m_rCurve.getWidth() * factorX) + m_pImg->getWidth(), (int)(m_rCurve.getHeight() * factorY) + m_pImg->getHeight(), - m_pImg->getWidth() / 2, - m_pImg->getHeight() / 2 ); } else notifyLayout(); }
void CtrlSliderBg::handleEvent( EvtGeneric &rEvent ) { if( rEvent.getAsString().find( "mouse:left:down" ) != string::npos ) { // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); // Get the position of the control const Position *pPos = getPosition(); // Get the value corresponding to the position of the mouse EvtMouse &rEvtMouse = (EvtMouse&)rEvent; int x = rEvtMouse.getXPos(); int y = rEvtMouse.getYPos(); m_rVariable.set( m_rCurve.getNearestPercent( (int)((x - pPos->getLeft()) / factorX), (int)((y - pPos->getTop()) / factorY) ) ); // Forward the clic to the cursor EvtMouse evt( getIntf(), x, y, EvtMouse::kLeft, EvtMouse::kDown ); TopWindow *pWin = getWindow(); if( pWin && m_pCursor ) { EvtEnter evtEnter( getIntf() ); // XXX It was not supposed to be implemented like that !! pWin->forwardEvent( evtEnter, *m_pCursor ); pWin->forwardEvent( evt, *m_pCursor ); } } 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 ); } }
void CtrlSliderCursor::onPositionChange() { // Compute the position of the cursor int xPos, yPos; m_rCurve.getPoint( m_rVariable.get(), xPos, yPos ); // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); xPos = (int)(xPos * factorX); yPos = (int)(yPos * factorY); const Position *pPos = getPosition(); int x = pPos->getLeft() + xPos - m_pImg->getWidth() / 2; int y = pPos->getTop() + yPos - m_pImg->getHeight() / 2; m_currentCursorRect = rect( x, y, m_pImg->getWidth(), m_pImg->getHeight() ); }
void CtrlSliderCursor::draw( OSGraphics &rImage, int xDest, int yDest ) { if( m_pImg ) { // Compute the position of the cursor int xPos, yPos; m_rCurve.getPoint( m_rVariable.get(), xPos, yPos ); // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); xPos = (int)(xPos * factorX); yPos = (int)(yPos * factorY); // Draw the current image rImage.drawGraphics( *m_pImg, 0, 0, xDest + xPos - m_pImg->getWidth() / 2, yDest + yPos - m_pImg->getHeight() / 2 ); } }
bool CtrlSliderCursor::mouseOver( int x, int y ) const { if( m_pImg ) { // Compute the position of the cursor int xPos, yPos; m_rCurve.getPoint( m_rVariable.get(), xPos, yPos ); // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); xPos = (int)(xPos * factorX); yPos = (int)(yPos * factorY); return m_pImg->hit( x - xPos + m_pImg->getWidth() / 2, y - yPos + m_pImg->getHeight() / 2 ); } else { return false; } }
void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h ) { if( !m_pImgSeq || m_bgWidth <=0 || m_bgHeight <= 0 ) return; // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); int width = m_bgWidth * m_nbHoriz - (int)(m_padHoriz * factorX); int height = m_bgHeight * m_nbVert - (int)(m_padVert * factorY); // Rescale the image with the actual size of the control if needed if( !m_pScaledBmp || m_pScaledBmp->getWidth() != width || m_pScaledBmp->getHeight() != height ) { delete m_pScaledBmp; m_pScaledBmp = new ScaledBitmap( getIntf(), *m_pImgSeq, width, height ); } // 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 const Position *pPos = getPosition(); rect region( pPos->getLeft(), pPos->getTop(), m_bgWidth - (int)(m_padHoriz * factorX), m_bgHeight - (int)(m_padVert * factorY) ); rect clip( xDest, yDest, w, h ); rect inter; if( rect::intersect( region, clip, &inter ) ) rImage.drawBitmap( *m_pScaledBmp, x + inter.x - region.x, y + inter.y - region.y, inter.x, inter.y, inter.width, inter.height ); }
void CtrlSliderCursor::refreshLayout( bool force ) { // Compute the position of the cursor int xPos, yPos; m_rCurve.getPoint( m_rVariable.get(), xPos, yPos ); // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); xPos = (int)(xPos * factorX); yPos = (int)(yPos * factorY); const Position *pPos = getPosition(); int x = pPos->getLeft() + xPos - m_pImg->getWidth() / 2; int y = pPos->getTop() + yPos - m_pImg->getHeight() / 2; rect region( x, y, m_pImg->getWidth(), m_pImg->getHeight() ); if( !force && region.x == m_currentCursorRect.x && region.y == m_currentCursorRect.y && region.width == m_currentCursorRect.width && region.height == m_currentCursorRect.height ) { return; } rect join; if( rect::join( m_currentCursorRect, region, &join ) ) { m_currentCursorRect = region; notifyLayout( join.width, join.height, join.x - pPos->getLeft(), join.y - pPos->getTop() ); } }