Beispiel #1
0
bool nglZipFS::GetChildren(const nglPath& rPath, std::list<nglPath>& rChildren)
{
  nglString p(rPath.GetVolumeLessPath());
  p.TrimLeft(_T('/'));
  //wprintf(_T("trimed path '%s'\n"), p.GetChars());
  nglPath path(p);
  Node* pNode = mRoot.Find(path);
  if (!pNode)
    return 0;

  std::list<nglZipFS::Node*>::iterator it;
  std::list<nglZipFS::Node*>::iterator end = pNode->mpChildren.end();
  for (it = pNode->mpChildren.begin(); it != end; ++it)
  {
    if (*it)
    {
      nglZipPath path(this, rPath.GetPathName().IsEmpty()? (*it)->mName : rPath.GetPathName() );
      if (!rPath.GetPathName().IsEmpty())
        path += nglPath((*it)->mName);

      rChildren.push_back(path);
    }
  }
  return rChildren.size();
}
nglInputDeviceLinux::nglInputDeviceLinux (const nglPath& rDevice) : nglInputDeviceInstance(), nglEvent()
{
  mFlags = Read|Error;
  mFD = open((char*)rDevice.GetPathName().GetChars(), O_RDONLY);
  if (mFD == -1)
    return;

  char byte;
  char name[128];

  // Get number of axes
  ioctl(mFD, JSIOCGAXES, &byte);
  mAxes.resize(byte);

  // Get number of buttons
  ioctl(mFD, JSIOCGBUTTONS, &byte);
  mButtons.resize(byte);

  // Fetch name
  if (ioctl(mFD, JSIOCGNAME(sizeof(name)), name) < 0)
    mName = "unkown";
  else
    mName = name;

  // Synthetize port name
  mPort.Format("%s", rDevice.GetPathName().GetChars());

  App->AddEvent(this);
}
Beispiel #3
0
bool nuiFileTree::isRoot(const nglPath& rPath)
{
  const nglString& pathName = rPath.GetPathName();
  
  return (
    rPath.GetParent().GetPathName().IsEmpty() || 
    !rPath.GetPathName().Compare(_T("/")) || 
    !rPath.GetParent().GetPathName().Compare(_T("/Volumes")) ||
    ((pathName.GetLength() == 3) && (pathName[1] == _T(':')) && (pathName[2] == _T('/')))
    );
}
Beispiel #4
0
nuiTexture::nuiTexture (const nglPath& rPath, nglImageCodec* pCodec)
: nuiObject(), mTextureID(0), mTarget(0), mRotated(false)
{
  if (SetObjectClass(_T("nuiTexture")))
    InitAttributes();

  mpImage = NULL;
  mpProxyTexture = NULL;
  
  float scale = 1.0f;
  nglPath p(rPath);
  nglString path(p.GetRemovedExtension());
  if (nuiGetScaleFactor() > 1)
  {
    nglString ext(p.GetExtension());
    nglString res(path);
    res.Add(_T("@2x.")).Add(ext);
    p = res;
    mpImage = new nglImage(p, pCodec);
    if (mpImage && mpImage->IsValid())
    {
      scale = 2.0f;
    }
    else
    {
      delete mpImage;
      mpImage = NULL;
    }
  }
  else if (path.GetRight(3) == _T("@2x"))
  {
    scale = 2.0;
  }

  
  if (!mpImage)
  {
    mpImage = new nglImage(rPath, pCodec);
  }

  mpSurface = NULL;
  mOwnImage = true;
  mForceReload = false;
  mRetainBuffer = mRetainBuffers;

  SetProperty(_T("Source"),rPath.GetPathName());
  mpTextures[rPath.GetPathName()] = this;

  Init();
  SetScale(scale);
}
Beispiel #5
0
bool nuiSWF::Load(const nglPath& rPath)
{
  std::string str(rPath.GetPathName().GetStdString());
  const char* pFlashMovieName = str.c_str();
  int  movie_version = 0;

  StopAutoDraw();

//  gameswf::get_movie_info(pFlashMovieName, &movie_version, &mWidth, &mHeight, &mFPS, &mFrames, &mTags);
//  if (movie_version == 0)
//  {
//    NGL_OUT(_T("error: can't get info about %s\n"), pFlashMovieName);
//    return false;
//  }
//  
//  if (mFPS <= 0.5f)
//  {
//    NGL_OUT(_T("Forcing %f FPS instead of 0\n"), mFPS);
//    mFPS = 12.0f;
//  }
//
//  NGL_OUT(_T("Flash file loaded successfully\nName %s\nVersion %i\nWidth %i\nHeight %i\nFPS %f\n"), pFlashMovieName, movie_version, mWidth, mHeight, mFPS);

  //computeMouseScale(mBounds.extent);

  // Load the actual movie.
  mpMovie = mpPlayer->create_movie(pFlashMovieName);
  if (mpMovie == NULL)
  {
    NGL_OUT(_T("error: can't create a movie from '%s'\n"), pFlashMovieName);
    return false;
  }

  movie_version = mpMovie->get_version();
  mWidth = mpMovie->get_width_pixels();
  mHeight = mpMovie->get_height_pixels();
  mFPS = mpMovie->get_frame_rate();
  mFrames = mpMovie->get_frame_count();
  NGL_OUT(_T("Flash file loaded successfully\nName %s\nVersion %i\nWidth %i\nHeight %i\nFPS %f\n"), pFlashMovieName, movie_version, mWidth, mHeight, mFPS);
  
  mpMovieInterface = mpMovie->create_instance();
  if (mpMovieInterface == NULL)
  {
    NGL_OUT(_T("error: can't create movie instance\n"));
    return false;
  }
  mpMovieInterface->add_ref();
    
  InvalidateLayout();
  return true;
}
Beispiel #6
0
nuiFrame::nuiFrame(const nglString& rName, const nglPath& rTexturePath, const nuiRect& rClientRect, const nuiColor& rColor)
: nuiDecoration(rName),
  mpTexture(NULL),
  mColor(rColor),
  mUseWidgetFrameColor(false),
  mClientRect(rClientRect)
{
  if (SetObjectClass(_T("nuiFrame")))
    InitAttributes();
	
  SetTexturePath(rTexturePath.GetPathName());
  mDebug = false;
  mInterpolated = true;
}
Beispiel #7
0
nuiImageDecoration::nuiImageDecoration(const nglString& rName, const nglPath& rTexturePath, const nuiRect& rClientRect, nuiPosition position, const nuiColor& rColor)
: nuiDecoration(rName),
  mpTexture(NULL),
  mPosition(position),
  mClientRect(rClientRect),
  mColor(rColor),
  mRepeatX(false),
  mRepeatY(false)
{
  if (SetObjectClass(_T("nuiImageDecoration")))
    InitAttributes();
	
  mpTexture = nuiTexture::GetTexture(rTexturePath);
  if (mpTexture)
    SetProperty(_T("Texture"), rTexturePath.GetPathName());
}
Beispiel #8
0
nglString nuiSound::GetStringID(const nglPath& rPath, nuiSound::Type type)
{
  nglString str = rPath.GetPathName();
  switch (type) 
  {
    case nuiSound::eStream:
      str += STREAM_SUFFIX;
      break;
      
    case nuiSound::eMemory:
      str += MEMORY_SUFFIX;
      break;
      
    default:
      NGL_ASSERT(0);
      break;
  }
  return str;
}
Beispiel #9
0
void Generator::DumpIncluder(const nglPath& rootSource, const nglPath& pngSource,const nglPath& codeSource, const nglPath& HincluderPath, const nglPath& CPPincluderPath, nglString& HincluderStr, nglString& CPPincluderStr)
{
  std::list<nglPath> children;
  std::list<nglPath>::iterator it;
  
  pngSource.GetChildren(&children);
  
  for (it = children.begin(); it != children.end(); ++it)
  {
    nglPath child = *it;
    
    if (!child.IsLeaf())
    {
      // recurs.
      DumpIncluder(rootSource, child, codeSource, HincluderPath, CPPincluderPath, HincluderStr, CPPincluderStr);
      continue;
    }
    
    if (child.GetExtension().Compare(_T("png"), false))
      continue;
    
    nglString node = child.GetPathName();
    node.DeleteLeft(rootSource.GetPathName().GetLength()+1);
    node.DeleteRight(nglPath(node).GetExtension().GetLength() +1);
    
    nglPath HdestPath = codeSource + nglPath(node);
    nglPath CPPdestPath = codeSource + nglPath(node);
    HdestPath = nglPath(HdestPath.GetPathName() + _T(".h"));
    CPPdestPath = nglPath(CPPdestPath.GetPathName() + _T(".cpp"));
    
    HdestPath.MakeRelativeTo(HincluderPath.GetParent());
    CPPdestPath.MakeRelativeTo(CPPincluderPath.GetParent());
    
    nglString tmp;
    tmp.Format(_T("#include \"%ls\"\n"), HdestPath.GetChars());
    HincluderStr.Append(tmp);
    tmp.Format(_T("#include \"%ls\"\n"), CPPdestPath.GetChars());
    CPPincluderStr.Append(tmp);
  }
  
}
Beispiel #10
0
void Generator::ParsePngFiles(const nglPath& rootSource, const nglPath& pngSource, const nglPath& codeSource)
{
  std::list<nglPath> children;
  pngSource.GetChildren(&children);
  
  std::list<nglPath>::iterator it;
  for (it = children.begin(); it != children.end(); ++it)
  {
    const nglPath& child = *it;
    
    if (!child.IsLeaf())
    {
      // recurs.
      ParsePngFiles(rootSource, child, codeSource);
      continue;
    }
    
    if (child.GetExtension().Compare(_T("png"), false))
      continue;
    
    nglString node = child.GetPathName();
    node.DeleteLeft(rootSource.GetPathName().GetLength()+1);
    node.DeleteRight(nglPath(node).GetExtension().GetLength() +1);
    
    nglPath destPath = codeSource + nglPath(node);
    
    NGL_OUT(_T("path '%ls', node '%ls' => destPath '%ls'\n"), child.GetChars(), node.GetChars(), destPath.GetChars());
    
    nglPath destDir = destPath.GetParent();
    if (!destDir.Exists())
      destDir.Create(true);
    
    // and call the generator tool to create .cpp and .h files
    nglString cmd;
    nglString space(_T(" "));
    cmd.Append(mTool).Append(_T(" ")).Append(child.GetChars()).Append(_T(" ")).Append(destPath.GetChars());
    NGL_OUT(_T("command : %ls\n"), cmd.GetChars());
    system(cmd.GetStdString().c_str());
  }
  
}
Beispiel #11
0
void nuiImageDecoration::SetTexturePath(nglPath path)
{
  SetProperty(_T("Texture"), path.GetPathName());
  nuiTexture* pOld = mpTexture;
  mpTexture = nuiTexture::GetTexture(path);
  if (!mpTexture || !mpTexture->IsValid())
  {
    NGL_OUT(_T("nuiImageDecoration::SetTexturePath warning : could not load graphic resource '%ls'\n"), path.GetChars());
    return;
  }
  
  if (GetSourceClientRect() == nuiRect(0,0,0,0))
    SetSourceClientRect(nuiRect(0, 0, mpTexture->GetWidth(), mpTexture->GetHeight()));
  if (pOld)
    pOld->Release();
  
  SetRepeatX(mRepeatX);
  SetRepeatY(mRepeatY);
  
  Changed();
}
Beispiel #12
0
void PreferencesBase::SetPath(const nglString& rKey, const nglString& rName, const nglPath& value, PreferencesTarget target)
{
  nuiXMLNode* pNode = OpenKey(rKey, target);
  pNode->SetAttribute(rName, value.GetPathName());
}
Beispiel #13
0
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();
}
Beispiel #14
0
bool nuiZipWriter::AddFile(const nglPath& rPath, const nglString& rPathInZip, const nglString& rComment)
{
  return AddFile(rPath.OpenRead(), rPathInZip.IsEmpty() ? rPath.GetPathName() : rPathInZip, rComment, true);
}
Beispiel #15
0
bool nuiTexture::CreateAtlasFromPath(const nglPath& rPath, int32 MaxTextureSize, int32 ForceAtlasSize, bool AutoTrim)
{
  //NGL_OUT(_T("nuiTexture::CreateAtlasFromPath(rPath = '%s', MaxTextureSize = %d, ForceAtlasSize = %d, AutoTrim = '%s')\n"), rPath.GetChars(), MaxTextureSize, ForceAtlasSize, YESNO(AutoTrim));
  MaxTextureSize *= nuiGetScaleFactor();
  ForceAtlasSize *= nuiGetScaleFactor();
  int32 offset = 0;
  if (ForceAtlasSize)
    offset = 1;

  //App->GetLog().SetLevel(_T("StopWatch"), 100);
  nuiStopWatch watch(_T("Create atlas"));
  std::vector<AtlasElem> images;
  
  GetAllImages(images, rPath, MaxTextureSize, ForceAtlasSize, AutoTrim);
  watch.AddIntermediate(_T("Got all images"));
  
  TEXTURE_PACKER::TexturePacker* packer = TEXTURE_PACKER::createTexturePacker();
  packer->setTextureCount(images.size() + offset);

  if (ForceAtlasSize)
    packer->addTexture(ForceAtlasSize - 2, 0); // -2 to account for the border padding
  
  for (uint32 i = 0; i < images.size(); i++)
  {
    const AtlasElem& rElem(images[i]);
    packer->addTexture(rElem.mpImage->GetWidth(), rElem.mpImage->GetHeight());
  }
  
  int32 width = 0, height = 0;
  int unused_area = packer->packTextures(width, height, true, true);
  watch.AddIntermediate(_T("Packed textures"));

  // Create image buffer:
  nglImageInfo info(width, height, 32);
  info.AllocateBuffer();
  // Clear buffer:
  memset(info.mpBuffer, 0, 4 * width * height);
  nuiTexture* pAtlas = nuiTexture::GetTexture(info);
  pAtlas->SetSource(rPath.GetPathName());
  
  // Finally, to retrieve the results, for each texture 0-(n-1) call 'getTextureLocation'.
  for (uint32 i = 0; i < images.size(); i++)
  {
    AtlasElem& rElem(images[i]);
    int x, y, w, h;
    bool rotated = packer->getTextureLocation(i + offset, x, y, w, h);
    if (rotated)
    {
      nglImage* pImg = rElem.mpImage->RotateRight();
      delete rElem.mpImage;
      rElem.mpImage = pImg;
    }

    NGL_OUT(_T("{%d, %d, %d, %d} %s %s\n"), x, y, w, h, TRUEFALSE(rotated), rElem.mPath.GetChars());
    
    nglCopyImage(pAtlas->GetImage()->GetBuffer(), x, y, width, height, info.mBitDepth, rElem.mpImage->GetBuffer(), rElem.mpImage->GetWidth(), rElem.mpImage->GetHeight(), rElem.mpImage->GetBitDepth(), false, false);
    nuiTexture* pTex = nuiTexture::CreateTextureProxy(rElem.mPath.GetPathName(), rPath.GetPathName(), nuiRect(x, y, w, h), rotated);
    delete rElem.mpImage;
  }

  TEXTURE_PACKER::releaseTexturePacker(packer);

  watch.AddIntermediate(_T("Done"));
  return true;
}
Beispiel #16
0
void MainWindow::Load(const nglPath& p)
{    
  mpScrollView->Clear();
  ///////////////////////////////

  nglString cmdline;
  //cmdline.Add("/usr/bin/nm -n -U -arch i386 ").Add(p.GetPathName()).Add(" | c++filt | c++filt -n");
  cmdline.Add("/usr/bin/nm -n -U ").Add(p.GetPathName()).Add(" | c++filt | c++filt -n");
  printf("Launching\n%ls\n", cmdline.GetChars());
  FILE * file = popen(cmdline.GetStdString().c_str(), "r");
  nglOMemory omem;
  uint32 res = 0;
  do
  {
    char buf[1025];
    memset(buf, 0, 1025);
    uint32 res = fread(buf, 1024, 1, file);
    //printf("%s", buf);
    omem.Write(buf, 1024, 1);
  } while (!feof(file));
  pclose(file);
  
  printf("redirection done\n");
  nglIStream* pStream = new nglIMemory(omem.GetBufferData(), omem.GetBufferSize());;
  
  nglString line;
  
  uint64 lastaddr = 0;
  nglString lastsymbol;
  
  std::map<nglString, Node*> methods;
  std::map<nglString, Node*> classes;
  
  printf("read result\n");
  while (pStream->ReadLine(line))
  {
    // Read address
    int32 c = 0;
    while (line[c] && line[c] != ' ')
      c++;
    nglString a(line.Extract(0, c));
    uint64 address = a.GetCUInt(16);

    c++;
    // Read type char
    nglChar type = line[c];
    
    // Read Symbol if we are on a method / function decl
    if (type == 't')
    {
      c++;

      if (!lastsymbol.IsEmpty())
      {
        uint64 lastsize = address - lastaddr;
        
        std::map<nglString, Node*>::iterator it = methods.find(lastsymbol);
        
        bool skip = false;
        Node* pMethod = NULL;
        if (it != methods.end())
        {
          pMethod = it->second;
          pMethod->SetSize(pMethod->GetSize() + lastsize);
          //it->second += lastsize;
          skip = true;
        }
        else
        {
          //NGL_OUT(_T("new method \t %ls\n"), lastsymbol.GetChars());
          pMethod = new Node(lastsymbol);
          pMethod->SetSize(lastsize);
          methods[lastsymbol] = pMethod;
        }
        
        NGL_ASSERT(pMethod != NULL);
        
        if (!skip) // The method already exist so no need to add it to its class
        {
          int32 pos = lastsymbol.Find(':');
          if (pos > 0 && lastsymbol[pos+1] == ':')
          {
            nglString classname = lastsymbol.GetLeft(pos);
            //NGL_OUT(_T("new class %ls\n"), classname.GetChars());
            
            std::map<nglString, Node*>::iterator it = classes.find(classname);
            Node* pNode = NULL;
            if (it != classes.end())
            {
              pNode = it->second;
              pNode->SetSize(it->second->GetSize() + lastsize);
            }
            else
            {
              pNode = new Node(classname);
              pNode->SetSize(lastsize);
              classes[classname] = pNode;
            }
            
            pNode->AddChild(pMethod);
          }
        }
      }
      
      lastaddr = address;
      lastsymbol = line.GetRight(line.GetLength() - c);
    }
  }
  printf("done\n");
  
  printf("build tree\n");
  delete pStream;
  
  std::list<std::pair<nglString, Node*> > sorted;
  {
    std::map<nglString, Node*>::const_iterator it = classes.begin();
    std::map<nglString, Node*>::const_iterator end = classes.end();
    
    while (it != end)
    {
      //NGL_OUT(_T("add unsorted %ls\n"), it->first.GetChars());
      sorted.push_back(std::pair<nglString, Node*>(it->first, it->second) );
      ++it;
    }
  }
  
  sorted.sort(cmp);
  
  nuiTreeNode* pTree = new nuiTreeNode(new nuiLabel(_T("Classes")));
  
  {
    std::list<std::pair<nglString, Node*> >::const_iterator it = sorted.begin();
    std::list<std::pair<nglString, Node*> >::const_iterator end = sorted.end();
    
    while (it != end)
    {
      //NGL_OUT(_T("%lld\t\t%ls\n"), it->second->GetSize(), it->first.GetChars());
      pTree->AddChild(it->second);
      ++it;
    }
  }
  
  nuiTreeView* pTreeView = new nuiTreeView(pTree);
  mpScrollView->AddChild(pTreeView);
  printf("done\n");
}