void SceneObjectParticleEmitter::SetData(const char *szName, const char *szType, float x, float y, int w, int h, bool bStart, bool bLoop)
{
	_type = SCENEOBJECT_PARTICLEEMITTER;
	strcpy(_szObjectName, szName);
	_fx = x;
	_fy = y;
   _w = w;
   _h = h;
   _bStart = bStart;
   
   // Init de l'émetteur
   if (strcmp(szType, "flake") == 0) {
      _lpParticleEmitter1 = new ParticleEmitter(x, y);  
      if (!_lpParticleEmitter1->SetParticleBitmap("particule-etoile2")) {
         showFileError ("particule-etoile2.png");
         return;
      }
      _lpParticleEmitter1->SetHeightEffect(w);
      _lpParticleEmitter1->SetEmitRate(1);
      _lpParticleEmitter1->SetType(VFX_FLAKE);
      _lpParticleEmitter1->AddSegment(_fx - (_w/2), _fy, _fx + (_w/2), _fy, _w/3);  /* create segment where emitter will move */
   }
   if (strcmp(szType, "fire") == 0) {
      _lpParticleEmitter1 = new ParticleEmitter(x, y);  
      if (!_lpParticleEmitter1->SetParticleBitmap("particle")) {
         showFileError ("particle.png");
         return;
      }
      _lpParticleEmitter1->SetEmitRate(2);
      _lpParticleEmitter1->SetType(VFX_FIRE);
      _lpParticleEmitter1->SetHeightEffect(w);
      _lpParticleEmitter1->AddSegment(_fx, _fy, _fx - (_w/2), _fy, 8);
      
      _lpParticleEmitter2 = new ParticleEmitter(x, y);  
      if (!_lpParticleEmitter2->SetParticleBitmap("particle")) {
         showFileError ("particle.png");
         return;
      }
      _lpParticleEmitter2->SetEmitRate(2);
      _lpParticleEmitter2->SetType(VFX_FIRE);
      _lpParticleEmitter2->SetHeightEffect(w);
      _lpParticleEmitter2->AddSegment(_fx, _fy, _fx + (_w/2), _fy, 8);
   }
   if (strcmp(szType, "creepingsmoke") == 0) {
      _lpCreepingEmitter = NULL;
   }
}
void SceneObjectImage::SetGlitch()
{
   // Glitch désactivé pour cette image
   if (!_bGlitch) {
      return;
   }
   // Pas de glitch sur le bouton "back"
   if (strcmp(_szObjectName, "back") == 0) {
      return;
   }
   _lpGlitchEmitter = new ParticleEmitter(_x + _w/2, _y + _h/2);  
   if (!_lpGlitchEmitter->SetParticleBitmap("glow")) {
      showFileError ("Cannot load particule-etoile2 for Glitch");
      return;
   }
   _lpGlitchEmitter->SetType(VFX_FOCUS);
   if (_bVisible) {
      _lpGlitchEmitter->Start();
   }
}
Esempio n. 3
0
void WebPage::handleBase64Download(QWebFrame* pWebFrame, QUrl url)
{
    // look for beginning of base64 data
    QString base64 = QString::fromUtf8("base64,");
    int pos = url.path().indexOf(base64);
    if (pos == -1)
    {
        LOG_ERROR_MESSAGE("Base64 designator not found in data url");
        return;
    }

    // extract the base64 data from the uri
    QString base64Data = url.path();
    base64Data.remove(0, pos + base64.length());
    QByteArray base64ByteArray(base64Data.toStdString().c_str());
    QByteArray byteArray = QByteArray::fromBase64(base64ByteArray);

    // find the a tag in the page with this href
    QWebElement aTag;
    QString urlString = url.toString(QUrl::None);
    QWebElementCollection aElements = pWebFrame->findAllElements(
                                          QString::fromUtf8("a"));
    for (int i=0; i<aElements.count(); i++)
    {
        QWebElement a = aElements.at(i);
        QString href = a.attribute(QString::fromUtf8("href"));
        href.replace(QChar::fromAscii('\n'), QString::fromUtf8(""));
        if (href == urlString)
        {
            aTag = a;
            break;
        }
    }

    // if no a tag was found then bail
    if (aTag.isNull())
    {
        LOG_ERROR_MESSAGE("Unable to finding matching a tag for data url");
        return;
    }

    // get the download attribute (default filename)
    QString download = aTag.attribute(QString::fromUtf8("download"));
    QString defaultFilename = defaultSaveDir_.absoluteFilePath(download);

    // prompt for filename
    QString filename = QFileDialog::getSaveFileName(
                           NULL,
                           tr("Download File"),
                           defaultFilename,
                           defaultSaveDir_.absolutePath(),
                           0,
                           standardFileDialogOptions());
    if (!filename.isEmpty())
    {
        // see if we need to force the extension
        FilePath defaultFilePath(defaultFilename.toUtf8().constData());
        FilePath chosenFilePath(filename.toUtf8().constData());
        if (chosenFilePath.extension().empty() &&
                !defaultFilePath.extension().empty())
        {
            filename += QString::fromStdString(defaultFilePath.extension());
        }

        // write the file
        QFile file(filename);
        if (file.open(QIODevice::WriteOnly))
        {
            if (file.write(byteArray) == -1)
            {
                showFileError(QString::fromUtf8("writing"),
                              filename,
                              file.errorString());
            }

            file.close();
        }
        else
        {
            showFileError(QString::fromUtf8("writing"),
                          filename,
                          file.errorString());
        }

        // persist the defaultSaveDir
        defaultSaveDir_ = QFileInfo(file).dir();
    }
}