コード例 #1
0
ファイル: nuiTranslator.cpp プロジェクト: YetToCome/nui3
bool nuiTranslator::LoadLanguage(const nglPath& rLanguageFile)
{
  nglIStream* pStream = rLanguageFile.OpenRead();
  if (!pStream)
    return false;
  
  bool res = LoadLanguage(pStream);
  
  delete pStream;
  
  return res;
}
コード例 #2
0
ファイル: ProjectGenerator.cpp プロジェクト: JamesLinus/nui3
bool ProjectGenerator::CopyDirectory(const nglPath& targetPath, const nglPath& srcpath)
{
  // create folder
  if (!targetPath.Create())
  {
    nglString msg;
    msg.Format(_T("creating target folder '%ls'"), targetPath.GetChars());
    return MsgError(msg);
  }
  
  
  std::list<nglPath> children;
  srcpath.GetChildren(&children);
  std::list<nglPath>::iterator it;
  for (it = children.begin(); it != children.end(); ++it)
  {
    const nglPath& srcpath = *it;
    
    if (!srcpath.IsLeaf())
      continue;
    
    nglPath dstpath = targetPath;
    dstpath += srcpath.GetNodeName();
    
    nglString contents;
    
    nglIStream* piFile = srcpath.OpenRead();
    if (!piFile)
    {
      nglString msg;
      msg.Format(_T("opening for reading input file '%ls'"), srcpath.GetChars());
      return MsgError(msg);
    }
    
    nglOStream* poFile = dstpath.OpenWrite(false);
    if (!poFile)
    {
      nglString msg;
      msg.Format(_T("opening for writing output file '%ls'"), dstpath.GetChars());
      return MsgError(msg);
    }
    
    piFile->PipeTo(*poFile);
    delete poFile;
    delete piFile;
    
    NGL_OUT(_T("nui project generator : created file '%ls'\n"), dstpath.GetChars());
  }
  
  return true;
}
コード例 #3
0
ファイル: nglZipFS.cpp プロジェクト: JamesLinus/nui3
nglZipFS::nglZipFS(const nglPath& rPath)
: nglVolume(nglPath(rPath.GetNodeName()).GetRemovedExtension(), nglString::Empty, nglString::Empty, nglPathVolume::ReadOnly, nglPathVolume::eTypeZip),
  mRoot(_T(""), 0, 0, 0, false), mpFileFuncDef(NULL)
{
  mpStream = rPath.OpenRead();
  mOwnStream = true;
  SetValid(mpStream != NULL);

	if (mpStream)
		mpStream->SetEndian(eEndianIntel);
	
  mpPrivate = new nglZipPrivate();
  NGL_ASSERT(mpPrivate);
}
コード例 #4
0
ファイル: nuiHugeImage.cpp プロジェクト: hamedmohammadi/nui3
bool nuiHugeImage::Load(const nglPath& rImagePath)
{
  ClearImage();
  
  // Load the big image:
  nglIStream* pStream = rImagePath.OpenRead();
  nglImage* pImage = new nglImage(pStream);
  delete pStream;
  if (!pImage)
    return false;
  
  int32 w = pImage->GetWidth();
  int32 h = pImage->GetHeight();

  mTextures.resize((w / TEXTURE_SIZE) + 1);

  mImageSize.Set(w, h);
  
  int32 i = 0;
  for (int32 x = 0; x < w; x += TEXTURE_SIZE, i++)
  {
    int32 j = 0;
    mTextures[i].resize((h / TEXTURE_SIZE) + 1);
    for (int32 y = 0; y < h; y += TEXTURE_SIZE, j++)
    {
      int32 sx = MIN(TEXTURE_SIZE, w - x);
      int32 sy = MIN(TEXTURE_SIZE, h - y);
      nglImage* pCrop = pImage->Crop(x, y, sx, sy);
      //NGL_OUT(_T("Crop[%d][%d] 0x%x\n"), i, j, pCrop);
      mTextures[i][j] = nuiTexture::GetTexture(pCrop, true);
//       mTextures[i][j]->EnableAutoMipMap(true);
//       mTextures[i][j]->SetMagFilter(GL_LINEAR);
//       mTextures[i][j]->SetMinFilter(GL_LINEAR_MIPMAP_LINEAR);
    }
  }
  
  delete pImage;
  
  mZoom = 1.0f;
  mX = w / 2;
  mY = h / 2;
  
  InvalidateLayout();
  return true;
}
コード例 #5
0
ファイル: ProjectGenerator.cpp プロジェクト: JamesLinus/nui3
bool ProjectGenerator::GenerateFile(const nglPath& src, const nglPath& dst)
{
  uint32 srcsize = (uint32)src.GetSize();
  
  nglIStream* pFile = src.OpenRead();
  if (!pFile)
  {
    nglString msg;
    msg.Format(_T("reading input file '%ls'"), src.GetChars());
    return MsgError(msg);
  }

  char* str = new char[srcsize + 1];
  pFile->Read(str, srcsize, 1);
  str[srcsize] = 0;
  delete pFile;
  
  nglString contents(str);
  contents.Replace(_T("TemplateApp"), mProjectName);
  contents.Replace(_T("../../../nui3"), mNuiRelativeSource.GetPathName());

  
  nglOStream* poFile = dst.OpenWrite(false);
  if (!poFile)
  {
    nglString msg;
    msg.Format(_T("writing output file '%ls'"), dst.GetChars());
    return MsgError(msg);
  }

  char* ptr = contents.Export();
  
  poFile->Write(ptr, contents.GetLength(), 1);
  delete poFile;
  if (ptr)
    free(ptr);

  NGL_OUT(_T("nui project generator : generated '%ls'\n"), dst.GetChars());
  return true;
}
コード例 #6
0
ファイル: MainWindow.cpp プロジェクト: JamesLinus/nui3
bool MainWindow::LoadCSS(const nglPath& rPath)
{
  nglIStream* pF = rPath.OpenRead();
  if (!pF)
  {
    NGL_OUT(_T("Unable to open CSS source file '%ls'\n"), rPath.GetChars());
    return false;
  }
  
  nuiCSS* pCSS = new nuiCSS();
  bool res = pCSS->Load(*pF, rPath);
  
  if (res)
  {
    SetCSS(pCSS);
    return true;
  }
  
  NGL_OUT(_T("%ls\n"), pCSS->GetErrorString().GetChars());
  
  delete pCSS;
  return false;
}
コード例 #7
0
ファイル: nglImage.cpp プロジェクト: hamedmohammadi/nui3
nglImage::nglImage (const nglPath& rPath, nglImageCodec* pCodec )
{
  StaticInit();
  mpCodec = pCodec;
  mOwnCodec = (pCodec == NULL);

  nglIStream* pIFile = rPath.OpenRead();
  if (!pIFile)
  {
    return;
  }
  
  if (pIFile->GetState() != eStreamReady)
  {
    delete pIFile;
    return;
  }

  if (!mpCodec)
  {
    uint32 count;
    count = mpCodecInfos->size();
    for (uint32 i=0; i<count && !mpCodec; i++)
    {
      if ((*mpCodecInfos)[i])
      {
        mpCodec = (*mpCodecInfos)[i]->CreateInstance(); // try to create a codec
        if (mpCodec) // success?
        {
          if (!mpCodec->Probe(pIFile)) // try to make the codec recognize the data.
          { // :-(
            delete mpCodec;
            mpCodec = NULL;
          }
        }
      }
    }
  }

  if (!mpCodec) // If not codec was able to detect the image format we try to match the file with its extension.
  {
    uint32 count = mpCodecInfos->size();
    nglString filename = rPath.GetPathName();
    for (uint32 i=0; i<count && !mpCodec; i++)
    {
      if ((*mpCodecInfos)[i])
      {
        if (!((*mpCodecInfos)[i]->ExtensionMatch (filename))) // success?
        {
          // :-(
          delete mpCodec;
          mpCodec = NULL;
        }
      }
    }
  }

  if (mpCodec)
  {
    mpCodec->Init(this);
    mpCodec->Feed(pIFile);
    if (mOwnCodec)
    {
      delete mpCodec;
      mpCodec = NULL;
      mOwnCodec = false;
    }
  }
  
  delete pIFile;

  if (IsValid() && !mInfo.mPreMultAlpha)
    PreMultiply();
}
コード例 #8
0
ファイル: nglZipFS.cpp プロジェクト: JamesLinus/nui3
bool nuiZipWriter::AddFile(const nglPath& rPath, const nglString& rPathInZip, const nglString& rComment)
{
  return AddFile(rPath.OpenRead(), rPathInZip.IsEmpty() ? rPath.GetPathName() : rPathInZip, rComment, true);
}