示例#1
0
    void run()
    {
        bool aborted = false;
        QString filename =  m_imageProperties.filename;

        // NOTE Do NOT use MythImageReader::supportsAnimation here, it defeats
        // the point of caching remote images
        if (ImageLoader::SupportsAnimation(filename))
        {
             AnimationFrames *frames;

             frames = ImageLoader::LoadAnimatedImage(m_painter,
                                                     m_imageProperties,
                                                     m_cacheMode, m_parent,
                                                     aborted);

             if (frames && frames->count() > 1)
             {
                ImageLoadEvent *le = new ImageLoadEvent(m_parent, frames,
                                                        m_basefile,
                                                        m_imageProperties.filename,
                                                        aborted);
                QCoreApplication::postEvent(const_cast<MythUIImage*>(m_parent), le);

                return;
             }
             delete frames;
        }

        MythImage *image = ImageLoader::LoadImage(m_painter,
                                                    m_imageProperties,
                                                    m_cacheMode, m_parent,
                                                    aborted);

        ImageLoadEvent *le = new ImageLoadEvent(m_parent, image, m_basefile,
                                                m_imageProperties.filename,
                                                m_number, aborted);
        QCoreApplication::postEvent(const_cast<MythUIImage*>(m_parent), le);
    }
示例#2
0
    static AnimationFrames *LoadAnimatedImage(MythPainter *painter,
                                               // Must be a copy for thread safety
                                              ImageProperties imProps,
                                              ImageCacheMode cacheMode,
                                               // Included only to check address, could be
                                               // replaced by generating a unique value for
                                               // each MythUIImage object?
                                              const MythUIImage *parent,
                                              bool &aborted)
    {
        QString filename = QString("frame-%1-") + imProps.filename;
        QString frameFilename;
        int imageCount = 1;

        MythImageReader *imageReader = new MythImageReader(imProps.filename);

        AnimationFrames *images = new AnimationFrames();

        while (imageReader->canRead() && !aborted)
        {
            frameFilename = filename.arg(imageCount);

            ImageProperties frameProps = imProps;
            frameProps.filename = frameFilename;

            MythImage *im = LoadImage(painter, frameProps, cacheMode, parent,
                                      aborted, imageReader);

            if (!im)
                aborted = true;

            images->append(AnimationFrame(im, imageReader->nextImageDelay()));
            imageCount++;
        }

        delete imageReader;

        return images;
    }
示例#3
0
//----------------------------------------------------------------------------
SampleChara::SampleChara()
{
	Node *helpNode = GetNodeHelp();
	if (helpNode) helpNode->Show(false);

	SetAnimType(AT_FRAMES);

	Node *rootNode = new0 Node();
	AttachChild(rootNode);
	rootNode->SetName("RootNode");

	Node *animNode = new0 Node();
	rootNode->AttachChild(animNode);
	animNode->SetName("AnimNode");

	AnimationFrames *anim = new0 AnimationFrames();
	anim->SetFilename("Data/Sample/images/wbdz/wbdz_Move/wbdz_Move.xml");
	AddAnim(anim);

	//SetHeading(AVector::UNIT_X);
	PlayAnim(anim);
}
示例#4
0
void MythUIImage::SetAnimationFrames(AnimationFrames frames)
{
    QVector<int> delays;
    QVector<MythImage *> images;

    AnimationFrames::iterator it;

    for (it = frames.begin(); it != frames.end(); ++it)
    {
        images.append((*it).first);
        delays.append((*it).second);
    }

    if (images.size())
    {
        SetImages(&images);

        if (m_Delay < 0  && delays.size())
            SetDelays(delays);
    }
    else
        Reset();
}
示例#5
0
void wxImagePanel::SetImages( const AnimationFrames& newImages )
{
    if( newImages.empty() )
        return;

    mFrames = newImages;
    mImageFactory.Reset();
    mBitmapCache.clear();

    mCurFrame = 0;
    SetImage( mFrames[ mCurFrame ].mImage );
    SetScale( mScale );

    if( mFrames.size() > 1 )
    {
        Play( false );
    }
}
示例#6
0
void wxImagePanel::SetImages( const AnimationFrames& newImages )
{
    if( newImages.empty() )
        return;

    mFrames = newImages;
    mImageFactory.Reset();
    mBitmapCache.clear();

    mCurFrame = 0;
    SetImage( mFrames[ mCurFrame ].mImage );
    SetZoomType( mZoomType );
    mPosition = ClampPosition( wxPoint( 0, 0 ) );

    if( mFrames.size() > 1 )
    {
        Play( false );
    }
}
示例#7
0
/**
*  \copydoc MythUIType::customEvent()
*/
void MythUIImage::customEvent(QEvent *event)
{
    if (event->type() == ImageLoadEvent::kEventType)
    {
        MythImage *image = NULL;
        AnimationFrames *animationFrames = NULL;
        int number = 0;
        QString filename;
        bool aborted;

        ImageLoadEvent *le = static_cast<ImageLoadEvent *>(event);

        if (le->GetParent() != this)
            return;

        image  = le->GetImage();
        number = le->GetNumber();
        filename = le->GetFilename();
        animationFrames = le->GetAnimationFrames();
        aborted = le->GetAbortState();

        m_runningThreads--;

        d->m_UpdateLock.lockForRead();

        // 1) We aborted loading the image for some reason (e.g. two requests
        //    for same image)
        // 2) Filename changed since we started this image, so abort to avoid
        // rendering two different images in quick succession which causes
        // unsightly flickering
        if (aborted ||
            (le->GetBasefile() != m_imageProperties.filename))
        {
            d->m_UpdateLock.unlock();

            if (aborted)
                LOG(VB_GUI, LOG_DEBUG, QString("Aborted loading image %1")
                                                                .arg(filename));

            if (image)
                image->DecrRef();

            if (animationFrames)
            {
                AnimationFrames::iterator it;

                for (it = animationFrames->begin(); it != animationFrames->end();
                     ++it)
                {
                    MythImage *im = (*it).first;
                    if (im)
                        im->DecrRef();
                }

                delete animationFrames;
            }

            return;
        }

        d->m_UpdateLock.unlock();

        if (animationFrames)
        {
            SetAnimationFrames(*animationFrames);

            delete animationFrames;

            return;
        }

        if (image)
        {
            // We don't clear until we have the new image ready to display to
            // avoid unsightly flashing. This isn't currently supported for
            // animations.
            if ((m_HighNum == m_LowNum) && !m_animatedImage)
                Clear();

            d->m_UpdateLock.lockForWrite();

            if (m_imageProperties.forceSize.isNull())
                SetSize(image->size());

            MythRect rect(GetFullArea());
            rect.setSize(image->size());
            SetMinArea(rect);

            d->m_UpdateLock.unlock();

            m_ImagesLock.lock();

            if (m_Images[number])
            {
                // If we got to this point, it means this same MythUIImage
                // was told to reload the same image, so we use the newest
                // copy of the image.
                m_Images[number]->DecrRef(); // delete the original
            }

            m_Images[number] = image;
            m_ImagesLock.unlock();

            SetRedraw();

            d->m_UpdateLock.lockForWrite();
            m_LastDisplay = QTime::currentTime();
            d->m_UpdateLock.unlock();

            return;
        }

        // No Images were loaded, so trigger Reset to default
        Reset();
    }
}