bool MainWindow::LoadCSS(const nglPath& rPath) { NGL_OUT("MainWindow::LoadCSS"); 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); delete pF; if (res) { nuiMainWindow::SetCSS(pCSS); NGL_OUT("MainWindow::LoadCSS OK"); return true; } NGL_OUT(_T("%ls\n"), pCSS->GetErrorString().GetChars()); delete pCSS; NGL_OUT("MainWindow::LoadCSS ERROR"); return false; }
nglString nuiFileTree::GetFileInfo(const nglPath& rPath) { nglString str; nglPathInfo info; rPath.GetInfo(info); // file modification date nglTimeInfo timeInfo; nglString timestr; nglTime lastMod = info.LastMod; lastMod.GetLocalTime(timeInfo); timestr.Format(_T("%d/%d/%d, %d:%d"), timeInfo.Year+1900, timeInfo.Month, timeInfo.Day, timeInfo.Hours, timeInfo.Minutes); str.Append(timestr); if (rPath.IsLeaf()) { // file size str.Append(_T(" - ")); FormatFileSize(info.Size, str); } return str; }
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); }
nuiSpriteDef::nuiSpriteDef(const nglPath& rSpriteDefPath) { Init(); nglString name(rSpriteDefPath.GetNodeName()); SetObjectName(name); std::map<nglString, nuiSpriteDef*>::const_iterator it = mSpriteMap.find(name); if (it != mSpriteMap.end()) it->second->Release(); mSpriteMap[name] = this; { std::list<nglPath> children; rSpriteDefPath.GetChildren(&children); std::list<nglPath>::const_iterator it = children.begin(); std::list<nglPath>::const_iterator end = children.end(); for (; it != end; it++) { nuiSpriteAnimation* pAnim = new nuiSpriteAnimation(*it); if (pAnim->GetFrameCount()) AddAnimation(pAnim); else delete pAnim; } } }
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(); }
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('/'))) ); }
void nuiMimeMultiPart::AddFile(const nglPath& rPath, const nglString& rVarName, const nglString& rFileName, ContentTransfertEncoding encoding) { nglString name(rFileName); if (name.IsNull()) name = rPath.GetNodeName(); nglIStream* pFile = rPath.OpenRead(); if (!pFile) return; AddFile(pFile, rVarName, name, encoding); }
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); }
bool nglZipPath::Decompose(const nglPath& rPath, std::list<nglPath>& rList) { nglPath parent(rPath.GetParent()); nglString tmp = rPath.GetNodeName(); nglPath node(tmp.IsNull()? nglString::Empty : tmp); if (parent == rPath) return true; rList.push_front(node); return Decompose(parent, rList); return true; }
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); }
bool nuiNativeResourceVolume::GetPathInfo(const nglPath& rPath, nglPathInfo& rInfo) { nglString tmp = rPath.GetVolumeLessPath(); nglPath path(tmp); tmp.TrimLeft(L'/'); nglPath trimmed(tmp); if (!path.GetPathName().Compare(_T("/"))) { // we act like this is a folder rInfo.Exists = true; ///< Node existence. All other fields are invalid if set to false. rInfo.IsLeaf = false; ///< Leaf (file or assimilable) or non-leaf (folder) rInfo.CanRead = true; ///< True if the file (leaf) can be read or the folder (non-leaf) can be traversed and its content listed rInfo.CanWrite = false; ///< True if the file (leaf) can be written to or a new node can be created in this folder (non-leaf) rInfo.LastAccess = 0; ///< nglTime stamp of last access (read or exec) rInfo.LastMod = 0; ///< nglTime stamp of last modification (write) rInfo.Size = 0; ///< If the node is a leaf, size in bytes. If non-leaf, always zero. rInfo.Visible = true; ///< Always visible... return true; } std::map<nglPath, std::set<nglString> >::const_iterator it = mItems.find(trimmed); if (it != mItems.end()) { // This is a folder rInfo.Exists = true; ///< Node existence. All other fields are invalid if set to false. rInfo.IsLeaf = false; ///< Leaf (file or assimilable) or non-leaf (folder) rInfo.CanRead = true; ///< True if the file (leaf) can be read or the folder (non-leaf) can be traversed and its content listed rInfo.CanWrite = false; ///< True if the file (leaf) can be written to or a new node can be created in this folder (non-leaf) rInfo.LastAccess = 0; ///< nglTime stamp of last access (read or exec) rInfo.LastMod = 0; ///< nglTime stamp of last modification (write) rInfo.Size = 0; ///< If the node is a leaf, size in bytes. If non-leaf, always zero. rInfo.Visible = true; ///< Always visible... return true; } nuiNativeResource* pRes = new nuiNativeResource(path); if (pRes && pRes->IsValid()) { // This is a file rInfo.Exists = true; ///< Node existence. All other fields are invalid if set to false. rInfo.IsLeaf = true; ///< Leaf (file or assimilable) or non-leaf (folder) rInfo.CanRead = true; ///< True if the file (leaf) can be read or the folder (non-leaf) can be traversed and its content listed rInfo.CanWrite = false; ///< True if the file (leaf) can be written to or a new node can be created in this folder (non-leaf) rInfo.LastAccess = 0; ///< nglTime stamp of last access (read or exec) rInfo.LastMod = 0; ///< nglTime stamp of last modification (write) rInfo.Size = pRes->Available(); ///< If the node is a leaf, size in bytes. If non-leaf, always zero. rInfo.Visible = true; ///< Always visible... delete pRes; return true; } delete pRes; return false; }
bool nuiNativeResourceVolume::GetChildren(const nglPath& rPath, std::list<nglPath>& rChildren) { nglString p(rPath.GetVolumeLessPath()); p.TrimLeft(_T('/')); //wprintf(_T("trimed path '%ls'\n"), p.GetChars()); nglPath path(p); //wprintf(_T("GetChildren(\"%ls\") [%ls] [%ls]\n"), rPath.GetChars(), path.GetChars(), p.GetChars()); std::map<nglPath, std::set<nglString> >::const_iterator fit = mItems.find(path); if (fit == mItems.end()) { // The path has to point to a folder, not a file return false; } const std::set<nglString>& rChildrenSet(fit->second); std::set<nglString>::const_iterator it = rChildrenSet.begin(); std::set<nglString>::const_iterator end = rChildrenSet.end(); while (it != end) { nglPath p(rPath); p += *it; rChildren.push_back(p); ++it; } return true; }
bool nuiTranslator::SaveLanguage(const nglPath& rOutputLanguageFile) const { nglOStream* pStream = rOutputLanguageFile.OpenWrite(true); bool res = SaveLanguage(pStream); delete pStream; return res; }
bool nuiTranslator::LoadLanguages(const nglPath& rLanguageFilesFolder) { mFiles.clear(); std::list<nglPath> Children; rLanguageFilesFolder.GetChildren(&Children); std::list<nglPath>::iterator it = Children.begin(); std::list<nglPath>::iterator end = Children.end(); while (it != end) { const nglPath& rPath(*it); NGL_OUT(_T("Localization file: %ls\n"), rPath.GetChars()); if (rPath.GetExtension() == _T("loc")) { nglPath p(rPath.GetNodeName()); nglString n(p.GetRemovedExtension()); mFiles[n] = rPath; } ++it; } return mFiles.empty(); }
nuiFileList::nuiFileList(const nglPath& rPath) : nuiList(nuiVertical), mFileListSink(this) { SetObjectClass(_T("nuiFileList")); nuiLabel* pLabel = new nuiLabel(_T("..")); pLabel->SetProperty(_T("Path"), rPath.GetParent().GetAbsolutePath().GetPathName()); Populate(rPath); mFileListSink.Connect(Activated, &nuiFileList::Selected, this); }
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); } }
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()); } }
nuiSVGView::nuiSVGView(const nglPath& rSource) : nuiWidget(), mCache(nuiRect()) { nuiSVGView::Init(); nglIStream* pFile = rSource.OpenRead(); if (pFile) { Load(*pFile); delete pFile; } }
bool nuiTranslator::LoadLanguage(const nglPath& rLanguageFile) { nglIStream* pStream = rLanguageFile.OpenRead(); if (!pStream) return false; bool res = LoadLanguage(pStream); delete pStream; return res; }
bool nuiList::PopulateDirs(const nglPath& rPath) { list<nglPath> FileList; rPath.GetChildren(&FileList); list<nglPath>::iterator it; list<nglPath>::iterator end = FileList.end(); for (it = FileList.begin(); it != end; ++it) { if (!(*it).IsLeaf()) { nuiLabel* pLabel = new nuiLabel(_T("[ ")+(*it).GetNodeName()+_T(" ]")); pLabel->SetProperty(_T("Path"),(*it).GetAbsolutePath().GetPathName()); AddChild(pLabel); } } SetProperty(_T("Path"),rPath.GetAbsolutePath().GetPathName()); return true; }
nuiSprite::nuiSprite(const nglPath& rSpriteDefPath, bool forceReplace) : mColor(255, 255, 255), mAlpha(1.0f), mBlendFunc(nuiBlendTransp) { mpSpriteDef = nuiSpriteDef::GetSprite(rSpriteDefPath.GetNodeName()); if (!mpSpriteDef || forceReplace) { mpSpriteDef = new nuiSpriteDef(rSpriteDefPath); mpSpriteDef->Acquire(); } NGL_ASSERT(mpSpriteDef); Init(); }
bool nuiImageDropZone::SetImage(const nglPath& rPath) { if (!rPath.Exists()) return false; mPath = rPath; mpImage->Trash(); mpImage = new nuiImage(mPath); AddChild(mpImage); return true; }
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; }
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; }
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; }
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()); }
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; }
bool nglZipFS::GetPathInfo(const nglPath& rPath, nglPathInfo& rInfo) { nglString p(rPath.GetVolumeLessPath()); p.TrimLeft(_T('/')); //wprintf(_T("trimed path '%s'\n"), p.GetChars()); nglPath path(p); Node* pChild = mRoot.Find(path); rInfo.Exists = pChild != NULL; rInfo.CanRead = rInfo.Exists; rInfo.CanWrite = false; rInfo.IsLeaf = (pChild != NULL) ? (pChild->mIsLeaf) : false; rInfo.Size = (pChild != NULL) ? (pChild->mSize) : 0; rInfo.Visible = true; ///< Always visible... return pChild != NULL; }
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; }
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(); }