void TimeLineCells::paintEvent( QPaintEvent* event ) { Q_UNUSED( event ); Object* object = mEditor->object(); Layer* layer = mEditor->layers()->currentLayer(); Q_ASSUME( object != nullptr && layer != nullptr ); QPainter painter( this ); bool isPlaying = mEditor->playback()->isPlaying(); if ( ( !isPlaying && !timeLine->scrubbing ) || m_pCache == NULL ) { drawContent(); } if ( m_pCache ) { painter.drawPixmap( QPoint( 0, 0 ), *m_pCache ); } if ( m_eType == TIMELINE_CELL_TYPE::Tracks ) { if (!isPlaying) { paintOnionSkin(painter); } // --- draw the position of the current frame if ( mEditor->currentFrame() > frameOffset ) { painter.setBrush( QColor( 255, 0, 0, 128 ) ); painter.setPen( Qt::NoPen ); painter.setFont( QFont( "helvetica", 10 ) ); //painter.setCompositionMode(QPainter::CompositionMode_Source); // this causes the message: QPainter::setCompositionMode: PorterDuff modes not supported on device QRect scrubRect; scrubRect.setTopLeft( QPoint( getFrameX( mEditor->currentFrame() - 1 ), 0 ) ); scrubRect.setBottomRight( QPoint( getFrameX( mEditor->currentFrame() ), height() ) ); if ( shortScrub ) { scrubRect.setBottomRight( QPoint( getFrameX( mEditor->currentFrame() ), 19 ) ); } painter.drawRect( scrubRect ); painter.setPen( QColor( 70, 70, 70, 255 ) ); int incr = 0; if ( mEditor->currentFrame() < 10 ) { incr = 4; } else { incr = 0; } painter.drawText( QPoint( getFrameX( mEditor->currentFrame() - 1 ) + incr, 15 ), QString::number( mEditor->currentFrame() ) ); } } }
void Player::initializeSprite(Graphics& graphics, const SpriteState& sprite_state) { units::Tile tile_y = getFrameY(sprite_state); units::Tile tile_x = getFrameX(sprite_state); sprites_[sprite_state] = std::unique_ptr<Sprite>{ new Sprite( graphics, kPlayerSpriteFilePath, units::tileToPixel(tile_x), units::tileToPixel(tile_y), units::tileToPixel(1), units::tileToPixel(1) ) }; }
void TimeLineCells::paintOnionSkin( QPainter& painter ) { Layer* layer = mEditor->layers()->currentLayer(); if (layer == nullptr) { return; } int frameNumber = mEditor->currentFrame(); int prevOnionSkinCount = mEditor->preference()->getInt(SETTING::ONION_PREV_FRAMES_NUM); int nextOnionSkinCount = mEditor->preference()->getInt(SETTING::ONION_NEXT_FRAMES_NUM); bool isAbsolute = (mEditor->preference()->getString(SETTING::ONION_TYPE) == "absolute"); if (mEditor->preference()->isOn(SETTING::PREV_ONION) && prevOnionSkinCount > 0) { int onionFrameNumber = layer->getPreviousFrameNumber(frameNumber, isAbsolute); int onionPosition = 0; while (onionPosition < prevOnionSkinCount && onionFrameNumber > 0) { painter.setBrush( QColor( 128, 128, 128, 128 ) ); painter.setPen( Qt::NoPen ); QRect onionRect; onionRect.setTopLeft( QPoint( getFrameX( onionFrameNumber - 1 ), 0 ) ); onionRect.setBottomRight( QPoint( getFrameX( onionFrameNumber ), height() ) ); onionRect.setBottomRight( QPoint( getFrameX( onionFrameNumber ), 19 ) ); painter.drawRect( onionRect ); onionFrameNumber = layer->getPreviousFrameNumber(onionFrameNumber, isAbsolute); onionPosition++; } } if (mEditor->preference()->isOn(SETTING::NEXT_ONION) && nextOnionSkinCount > 0) { int onionFrameNumber = layer->getNextFrameNumber(frameNumber, isAbsolute); int onionPosition = 0; while (onionPosition < nextOnionSkinCount && onionFrameNumber > 0) { painter.setBrush( QColor( 128, 128, 128, 128 ) ); painter.setPen( Qt::NoPen ); QRect onionRect; onionRect.setTopLeft( QPoint( getFrameX( onionFrameNumber - 1 ), 0 ) ); onionRect.setBottomRight( QPoint( getFrameX( onionFrameNumber ), height() ) ); onionRect.setBottomRight( QPoint( getFrameX( onionFrameNumber ), 19 ) ); painter.drawRect( onionRect ); onionFrameNumber = layer->getNextFrameNumber(onionFrameNumber, isAbsolute); onionPosition++; } } }
void TimeLineCells::drawContent() { if ( m_pCache == NULL ) { m_pCache = new QPixmap( size() ); if ( m_pCache->isNull() ) { // fail to create cache return; } } QPainter painter( m_pCache ); Object* object = mEditor->object(); Q_ASSERT_X( object != nullptr, "", "" ); Layer* layer = object->getLayer( mEditor->layers()->currentLayerIndex() ); if ( layer == NULL ) return; // grey background of the view painter.setPen( Qt::NoPen ); painter.setBrush( Qt::lightGray ); painter.drawRect( QRect( 0, 0, width(), height() ) ); // --- draw layers of the current object for ( int i = 0; i < object->getLayerCount(); i++ ) { if ( i != mEditor->layers()->currentLayerIndex() ) { Layer* layeri = object->getLayer( i ); if ( layeri != NULL ) { switch ( m_eType ) { case TIMELINE_CELL_TYPE::Tracks: layeri->paintTrack( painter, this, m_offsetX, getLayerY( i ), width() - m_offsetX, getLayerHeight(), false, frameSize ); break; case TIMELINE_CELL_TYPE::Layers: layeri->paintLabel( painter, this, 0, getLayerY( i ), width() - 1, getLayerHeight(), false, mEditor->allLayers() ); break; } } } } if ( abs( getMouseMoveY() ) > 5 ) { if ( m_eType == TIMELINE_CELL_TYPE::Tracks ) { layer->paintTrack( painter, this, m_offsetX, getLayerY( mEditor->layers()->currentLayerIndex() ) + getMouseMoveY(), width() - m_offsetX, getLayerHeight(), true, frameSize ); } if ( m_eType == TIMELINE_CELL_TYPE::Layers ) { layer->paintLabel( painter, this, 0, getLayerY( mEditor->layers()->currentLayerIndex() ) + getMouseMoveY(), width() - 1, getLayerHeight(), true, mEditor->allLayers() ); } painter.setPen( Qt::black ); painter.drawRect( 0, getLayerY( getLayerNumber( endY ) ) - 1, width(), 2 ); } else { if ( m_eType == TIMELINE_CELL_TYPE::Tracks ) { layer->paintTrack( painter, this, m_offsetX, getLayerY( mEditor->layers()->currentLayerIndex() ), width() - m_offsetX, getLayerHeight(), true, frameSize ); } if ( m_eType == TIMELINE_CELL_TYPE::Layers ) { layer->paintLabel( painter, this, 0, getLayerY( mEditor->layers()->currentLayerIndex() ), width() - 1, getLayerHeight(), true, mEditor->allLayers() ); } } // --- draw top painter.setPen( Qt::NoPen ); painter.setBrush( QColor( 220, 220, 220 ) ); painter.drawRect( QRect( 0, 0, width() - 1, m_offsetY - 1 ) ); painter.setPen( Qt::gray ); painter.drawLine( 0, 0, width() - 1, 0 ); painter.drawLine( 0, m_offsetY - 2, width() - 1, m_offsetY - 2 ); painter.setPen( Qt::lightGray ); painter.drawLine( 0, m_offsetY - 3, width() - 1, m_offsetY - 3 ); painter.drawLine( 0, 0, 0, m_offsetY - 3 ); if ( m_eType == TIMELINE_CELL_TYPE::Layers ) { // --- draw circle painter.setPen( Qt::black ); if ( mEditor->allLayers() == 0 ) { painter.setBrush( Qt::NoBrush ); } if ( mEditor->allLayers() == 1 ) { painter.setBrush( Qt::darkGray ); } if ( mEditor->allLayers() == 2 ) { painter.setBrush( Qt::black ); } painter.setRenderHint( QPainter::Antialiasing, true ); painter.drawEllipse( 6, 4, 9, 9 ); painter.setRenderHint( QPainter::Antialiasing, false ); } else if ( m_eType == TIMELINE_CELL_TYPE::Tracks ) { // --- draw ticks painter.setPen( QColor( 70, 70, 70, 255 ) ); painter.setBrush( Qt::darkGray ); painter.setFont( QFont( "helvetica", 10 ) ); int incr = 0; int fps = mEditor->playback()->fps(); for ( int i = frameOffset; i < frameOffset + ( width() - m_offsetX ) / frameSize; i++ ) { incr = ( i < 9 ) ? 4 : 0; if(i + 1 >= timeLine->getRangeLower() && i < timeLine->getRangeUpper()) { painter.setPen( Qt::NoPen ); painter.setBrush( Qt::yellow ); painter.drawRect( getFrameX( i ), 1, frameSize + 1, 2 ); painter.setPen( QColor( 70, 70, 70, 255 ) ); painter.setBrush( Qt::darkGray ); } if ( i%fps == 0 ) { painter.drawLine( getFrameX( i ), 1, getFrameX( i ), 5 ); } else if ( i%fps == fps / 2 ) { painter.drawLine( getFrameX( i ), 1, getFrameX( i ), 5 ); } else { painter.drawLine( getFrameX( i ), 1, getFrameX( i ), 3 ); } if ( i == 0 || i%fps == fps - 1 ) { painter.drawText( QPoint( getFrameX( i ) + incr, 15 ), QString::number( i + 1 ) ); } } // --- draw left border line painter.setPen( Qt::darkGray ); painter.drawLine( 0, 0, 0, height() ); } }
void TimeLineCells::updateFrame( int frameNumber ) { int x = getFrameX( frameNumber ); update( x - frameSize, 0, frameSize + 1, height() ); }