Exemplo n.º 1
0
void CMyAgendaNotifierSubject::ConstructL()
	{
	//Get the system filesession	
	RFs& fs = CEikonEnv::Static()->FsSession(); 
	//Get the file finder 
	TFindFile* findFile=new(ELeave) TFindFile(fs);
    CleanupStack::PushL(findFile);
	//File name parser
	TParse* fileNameParser=new(ELeave) TParse;
    CleanupStack::PushL(fileNameParser);

	//search for all rsc files in *\system\libs\plugins\*.rsc
	CDir* directory=NULL;
	User::LeaveIfError(findFile->FindWildByDir(KResFileName1, KResFileNamePath, directory));
	CleanupStack::PushL(directory);

	const TEntry& entry=(*directory)[directory->Count()-1];
	fileNameParser->Set(entry.iName,&findFile->File(),NULL);
	TFileName resourceFileName(fileNameParser->FullName());

	BaflUtils::NearestLanguageFile(iCoeEnv->FsSession(),resourceFileName);
	RDebug::Print(_L("Resource file name [%S]"),&resourceFileName);
	TInt offset=iEikonEnv->AddResourceFileL(resourceFileName);
	CleanupStack::PopAndDestroy(3);

	TRAPD(err,ConstructSleepingAlertDialogL(R_AGENDA_ALARM));
	iEikonEnv->DeleteResourceFile(offset);
	User::LeaveIfError(err);
	}
Exemplo n.º 2
0
osg::Geode* gsn::buildIconGeode(const char *resourceName)
{
  //alright this sucks. getting svg icons onto geode is a pain.
  //I tried something I found on the web, but looks like ass.
  //the openscenegraph svg reader only takes a filename.
  //so we will write out the resource files to the temp directory
  //so we can pass a file name to the svg reader. I don't like it either.
  QString alteredFileName(resourceName);
  alteredFileName.remove(":");
  alteredFileName.replace("/", "_");
  QDir tempDirectory = QDir::temp();
  QString resourceFileName(tempDirectory.absolutePath() + "/" + alteredFileName);
  if (!tempDirectory.exists(alteredFileName))
  {
    QFile resourceFile(resourceName);
    if (!resourceFile.open(QIODevice::ReadOnly | QIODevice::Text))
      qDebug() << "couldn't resource file";
    QByteArray buffer = resourceFile.readAll();
    resourceFile.close();
     
    QFile newFile(resourceFileName);
    if (!newFile.open(QIODevice::WriteOnly | QIODevice::Text))
      qDebug() << "couldn't open new temp file";
    qDebug() << "newfilename is: " << resourceFileName;
    newFile.write(buffer);
    newFile.close();
  }
  
  
  
  osg::ref_ptr<osg::Image> image = osgDB::readImageFile(resourceFileName.toStdString());
  assert(image.valid());
  
  osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D();
  texture->setImage(image);
  texture->setDataVariance(osg::Object::DYNAMIC);
  texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
  texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
  texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
  texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
  
  osg::Vec2Array* textureCoordinates = new osg::Vec2Array();
  
  double radius = 32.0;
  double sides = 32.0;
  osg::Vec3d currentPoint(radius, 0.0, 0.0);
  std::vector<osg::Vec3d> points;
  points.push_back(osg::Vec3d(0.0, 0.0, 0.0));
  textureCoordinates->push_back(osg::Vec2(0.5, 0.5));
  osg::Quat rotation(2 * M_PI / sides , osg::Vec3d(0.0, 0.0, 1.0));
  for (int index = 0; index < sides; ++index)
  {
    points.push_back(currentPoint);
    osg::Vec3 tempPointVec(currentPoint);
    tempPointVec.normalize();
    osg::Vec2 tempTextVec(tempPointVec.x(), tempPointVec.y());
    textureCoordinates->push_back((tempTextVec * 0.5) + osg::Vec2(0.5, 0.5));
    currentPoint = rotation * currentPoint;
  }
  points.push_back(osg::Vec3d(radius, 0.0, 0.0));
  textureCoordinates->push_back(textureCoordinates->at(1));
  
  osg::ref_ptr<osg::BlendFunc> blendFunc = new osg::BlendFunc;
  blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
  osg::Geometry *geometry = new osg::Geometry();
  geometry->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture.get());
  geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
  geometry->getOrCreateStateSet()->setAttributeAndModes(blendFunc);
  geometry->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
  
  osg::Vec3Array *vertices = new osg::Vec3Array();
  std::vector<osg::Vec3d>::const_iterator it;
  for (it = points.begin(); it != points.end(); ++it)
    vertices->push_back(*it);
  geometry->setVertexArray(vertices);
  
  geometry->setTexCoordArray(0, textureCoordinates);
  
  osg::Vec3Array *normals = new osg::Vec3Array();
  normals->push_back(osg::Vec3(0.0, 0.0, 1.0));
  geometry->setNormalArray(normals);
  geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
  
  geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN, 0, vertices->size()));
  
  osg::Geode *geode = new osg::Geode();
  geode->addDrawable(geometry);
  return geode;
  
/* this was looking terrible
    QImage qImageBase(resourceName);
    //I am hoping that osg will free this memory.
    QImage *qImage = new QImage(QGLWidget::convertToGLFormat(qImageBase));
    unsigned char *imageData = qImage->bits();
    osg::ref_ptr<osg::Image> osgImage = new osg::Image();
    osgImage->setImage(qImage->width(), qImage->height(), 1, GL_RGBA, GL_RGBA,
                       GL_UNSIGNED_BYTE, imageData, osg::Image::USE_NEW_DELETE, 1);
    osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
    texture->setImage(osgImage.get());

    float width = static_cast<float>(qImage->width());
    float height = static_cast<float>(qImage->height());
    osg::ref_ptr<osg::Drawable> quad = osg::createTexturedQuadGeometry
            (osg::Vec3(width/-2.0, height/-2.0, 0.0), osg::Vec3(width, 0.0, 0.0f),
             osg::Vec3(0.0, height, 0.0f));
    quad->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture.get());
    quad->getOrCreateStateSet()->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
*/
}