void MainWindow::OnCreation() { nuiHTTPRequest request(_T("http://127.0.0.1:8888/"), _T("POST")); nuiMimeMultiPart mime; mime.AddVariable(_T("MyParam"), _T("MyValue")); mime.AddFile(_T("rsrc:/css/main.css"), _T("MyFile")); mime.Dump(&request); nuiHTTPResponse* pRes = request.SendRequest(); nuiHTMLView* pView = new nuiHTMLView(); AddChild(pView); if (pRes) { NGL_OUT(_T("Result:\n%ls\n"), pRes->GetBodyStr().GetChars()); pView->SetText(pRes->GetBodyStr()); } else { NGL_OUT(_T("Unable to send HTTP Request")); pView->SetText(_T("Unable to send HTTP Request. Make sure you have launched the local *AMP (* Apache + Mysql + Php) server with the correct doc root.")); } delete pRes; }
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; }
nuiRect nuiFlowView::CalcIdealSize() { if (mCurrentIdealWidth == 0) { if (GetObjectName() == "Grid") { NGL_OUT("Flow Layout %p '%s'\n", this, GetObjectName().GetChars()); } } if (mIdealWidth > 0) { mCurrentIdealWidth = mIdealWidth; } else if (mRect.GetWidth() > 0) { mCurrentIdealWidth = mRect.GetWidth(); } nuiRect idealsize = Layout(false, mCurrentIdealWidth); if (GetDebug()) { NGL_OUT(_T("nuiFlowView::CalcIdealSize[%f]: %s\n"), mCurrentIdealWidth, idealsize.GetValue().GetChars()); } return idealsize; }
bool nuiGLPainter::CheckFramebufferStatus() { // return true; #if 1 GLint status = glCheckFramebufferStatusNUI(GL_FRAMEBUFFER_NUI); #if defined(NGL_DEBUG) switch (status) { case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_NUI: { NGL_OUT(_T("GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT\n")); } break; case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_NUI: { NGL_OUT(_T("GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT\n")); } break; case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_NUI: { NGL_OUT(_T("GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS\n")); } break; case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_NUI: { NGL_OUT(_T("GL_FRAMEBUFFER_INCOMPLETE_FORMATS\n")); } break; case GL_FRAMEBUFFER_UNSUPPORTED_NUI: { NGL_OUT(_T("GL_FRAMEBUFFER_UNSUPPORTED\n")); } break; } #endif return (status == GL_FRAMEBUFFER_COMPLETE_NUI); #endif }
void nuiTessellator::InternalTessError(GLenum ErrNo) { #ifdef __NUI_NO_GL__ NGL_OUT(_T("nui_glu tessellation error\n")); #elsif !defined(_OPENGL_ES_) NGL_OUT(_T("nui_glu tessellation error: %s\n"), gluErrorString(ErrNo)); #endif }
// Error callback for handling gameswf messages. static void log_callback(bool error, const char* message) { #ifdef _DEBUG_ if (error) { NGL_OUT(_T("ERROR from GameSWF: %s\n"), message); } else { NGL_OUT(_T("GameSWF> %s\n"), message); } #endif }
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; }
void TestVariant() { bool b1 = is_base_of<nuiObject, nuiWidget>::value; bool b2 = is_base_of<nuiWidget, nuiObject>::value; bool b3 = is_base_of<nuiObject*, nuiWidget*>::value; bool b4 = is_base_of<nuiWidget*, nuiObject*>::value; bool b5 = is_base_of<nuiObject, nuiObject>::value; bool b6 = is_base_of<nuiWidget, nuiWidget>::value; nuiVariant s1(12); nuiVariant s2(12.34); nuiVariant s3(-10); nuiVariant s4(nglString(_T("ProutString"))); nuiVariant s5(new nuiObject()); nuiVariant s6(new nuiWidget()); int r = s1; nglString r0 = s3; nglString r1 = s4; nuiObject* pObj1 = s5; nuiObject* pObj2 = s6; nuiWidget* pW1 = s5; nuiWidget* pW2 = s6; NGL_OUT(_T("sizeof nuiVariant: %d\n"), sizeof(nuiVariant)); }
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(); }
bool nuiTranslator::LoadLanguage(nglIStream* pStream) { nuiCSV csv(_T(',')); bool res = csv.Load(pStream); if (!res) return false; const std::vector<std::vector<nglString> >& rDoc(csv.GetDocument()); uint32 count = 0; for (uint32 i = 0; i < rDoc.size(); i++) { const std::vector<nglString>& rLine(rDoc[i]); if (rLine.size() >= 3) { AddSentence(rLine[0], rLine[1], rLine[2]); count++; } } NGL_OUT(_T("Loaded %d translated sentences from %d lines\n"), count, rDoc.size()); return true; }
void nuiAsyncIStream::Cancel() { NGL_OUT(_T("Canceling nuiAsyncIStream 0x%p"), this); mCancel = true; if (mpHandler) mpHandler->Cancel(); }
void MainWindow::OnButtonPressed(const nuiEvent& rEvent) { NGL_OUT("MainWindow::OnButtonPressed"); int64 tag = (int64)rEvent.mpUser; nglString msg; switch (tag) { case TAG_BUTTON1: msg = _T("a simple button\nwith a 'nuiCenter' position"); break; case TAG_BUTTON2: msg = _T("the same simple button\nbut with a 'nuiFill' position"); break; case TAG_BUTTON3: msg = _T("a simple button\nwith an image inside"); break; case TAG_BUTTON4: msg = _T("a rollover button\nusing three decorations"); break; } mpLabel->SetText(msg); rEvent.Cancel(); }
void MainWindow::OnTogglePressed(const nuiEvent& rEvent) { NGL_OUT("MainWindow::OnTogglePressed"); int64 tag = (int64)rEvent.mpUser; nglString msg; switch (tag) { case TAG_TOGGLEBUTTON1: msg = _T("a simple togglebutton, pressed"); break; case TAG_TOGGLEBUTTON2: msg = _T("a simple togglebutton, released"); break; case TAG_TOGGLEBUTTON3: msg = _T("a checkbox, pressed"); break; case TAG_TOGGLEBUTTON4: msg = _T("a checkbox, released"); break; } mpLabel->SetText(msg); rEvent.Cancel(); }
void nuiUniformDesc::Dump() const { nglString v; int32 count = 0; switch (mType) { case GL_FLOAT: count = 1; break; case GL_FLOAT_VEC2: count = 2; break; case GL_FLOAT_VEC3: count = 3; break; case GL_FLOAT_VEC4: count = 4; break; case GL_FLOAT_MAT2: count = 2 * 2; break; case GL_FLOAT_MAT3: count = 3 * 3; break; case GL_FLOAT_MAT4: count = 4 * 4; break; case GL_INT: count = 1; break; case GL_INT_VEC2: count = 2; break; case GL_INT_VEC3: count = 3; break; case GL_INT_VEC4: count = 4; break; case GL_UNSIGNED_INT: count = 1; break; case GL_SAMPLER_2D: count = 1; break; case GL_SAMPLER_CUBE: count = 1; break; default: NGL_ASSERT(0); } for (int32 i = 0; i < count * mCount; i++) v.Add(mValues.mpFloats[i]).Add(" "); NGL_OUT("%s: %s\n", mName.GetChars(), v.GetChars()); }
MainWindow::MainWindow(const nglContextInfo& rContextInfo, const nglWindowInfo& rInfo, bool ShowFPS, const nglContext* pShared ) : nuiMainWindow(rContextInfo, rInfo, pShared, nglPath(ePathCurrent)), mEventSink(this) { NGL_OUT("MainWindow::MainWindow"); SetDebugMode(true); LoadCSS(_T("rsrc:/css/main.css")); }
void nuiFrame::SetTexturePath(const nglPath& rPath) { mTexturePath = rPath; nuiTexture* pOld = mpTexture; mpTexture = nuiTexture::GetTexture(rPath); if (!mpTexture || !mpTexture->IsValid()) { NGL_OUT(_T("nuiFrame::SetTexturePath warning : could not load graphic resource '%ls'\n"), rPath.GetChars()); return; } if (GetSourceClientRect() == nuiRect(0,0,0,0)) SetSourceClientRect(nuiRect(0, 0, mpTexture->GetWidth(), mpTexture->GetHeight())); if (pOld) pOld->Release(); if (mInterpolated) { mpTexture->SetMinFilter(GL_LINEAR); mpTexture->SetMagFilter(GL_LINEAR); } else { mpTexture->SetMinFilter(GL_NEAREST); mpTexture->SetMagFilter(GL_NEAREST); } Changed(); }
void MainWindow::OnClose() { NGL_OUT("MainWindow::OnClose"); if (GetNGLWindow()->IsInModalState()) return; App->Quit(); }
nuiWidget* MainWindow::Tutorial_Buttons() { NGL_OUT("MainWindow::Tutorial_Buttons"); nuiHBox* pBox = new nuiHBox(0); //pBox->EnableSurface(true); // a simple button nuiButton* pBtn = new nuiButton(_T("button")); pBtn->SetObjectName(_T("MyButton")); mEventSink.Connect(pBtn->Activated, &MainWindow::OnButtonPressed, (void*)TAG_BUTTON1); pBox->AddCell(pBtn, nuiCenter); // a simple button filling the box's cell pBtn = new nuiButton(_T("button")); pBtn->SetObjectName(_T("MyButton")); pBox->AddCell(pBtn, nuiFill); mEventSink.Connect(pBtn->Activated, &MainWindow::OnButtonPressed, (void*)TAG_BUTTON2); // a button with an image nglImage pImg(_T("rsrc:/decorations/button1.png")); pBtn = new nuiButton(pImg); pBtn->SetObjectName(_T("MyButton")); pBox->AddCell(pBtn); mEventSink.Connect(pBtn->Activated, &MainWindow::OnButtonPressed, (void*)TAG_BUTTON3); // a roll-over button using decorations nuiGradientDecoration* pDecoUp = new nuiGradientDecoration(_T("DecoUp"), nuiColor(192,192,192), nuiColor(128,128,128), 1, nuiColor(0,0,0), eStrokeAndFillShape); nuiColorDecoration* pDecoUpHover = new nuiColorDecoration(_T("DecoUpHover"), nuiColor(255,0,0,128), 1, nuiColor(0,0,0)); nuiFrame* pFrame = new nuiFrame(_T("DecoDown"), _T("rsrc:/decorations/button1.png"), nuiRect(0,0,57,54)); // create a nuiStateDecoration using the three previous decorations for the rollover's three states : up, hover and done nuiStateDecoration* pStateDeco = new nuiStateDecoration(_T("Deco"), _T("DecoUp"), _T("DecoDown"), _T("DecoUpHover")); pBtn = new nuiButton(pStateDeco); pBtn->SetObjectName(_T("MyButton")); pBtn->SetUserSize(40,40); pBox->AddCell(pBtn, nuiCenter); mEventSink.Connect(pBtn->Activated, &MainWindow::OnButtonPressed, (void*)TAG_BUTTON4); NGL_OUT("MainWindow::Tutorial_Buttons ok"); return pBox; }
bool ProjectGenerator::MsgError(const nglString& error) { nglString msg; msg.Format(_T("error %ls"), error.GetChars()); NGL_OUT(msg); nuiMessageBox* pMessageBox = new nuiMessageBox(GetMainWindow(), _T("Project Creator"), msg, eMB_OK); pMessageBox->QueryUser(); return false; }
void MainWindow::OnRadioPressed(const nuiEvent& rEvent) { NGL_OUT("MainWindow::OnRadioPressed"); int64 index = (int64)rEvent.mpUser; nglString msg; msg.Format(_T("radio button #%d"), index); mpLabel->SetText(msg); rEvent.Cancel(); }
int nuiPath::AddVertexOptim(const nuiPoint& rPoint) { if (!rPoint.IsValid()) { NGL_OUT(_T("Invalid path point: {%f, %f, %f, %f}\n"), rPoint[0], rPoint[1], rPoint[2], rPoint[3]); NGL_ASSERT(false); } if (mVertices.empty() || !(rPoint == mVertices.back())) mVertices.push_back(rPoint); return mVertices.size()-1; }
// second set : classic radio button, using a radiobutton group nuiWidget* MainWindow::Tutorial_RadioButtons2() { NGL_OUT("MainWindow::Tutorial_RadioButtons2"); nuiHBox* pBox = new nuiHBox(0); for (int index = 0; index < 3; index++) { nuiRadioButton* pRadioBut = new nuiRadioButton(); // leave it without any child : it'll get a class "radio" look pRadioBut->SetObjectName(_T("MyButton")); pRadioBut->SetPosition(nuiCenter); pBox->AddCell(pRadioBut); pRadioBut->SetGroup(_T("radios2")); mEventSink.Connect(pRadioBut->Activated, &MainWindow::OnRadioPressed, (void*)index); } NGL_OUT("MainWindow::Tutorial_RadioButtons2 OK"); return pBox; }
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()); } }
void MainWindow::AddMessage(const nglChar* pFormat, ...) { va_list args; nglString buf; va_start(args, pFormat); buf.Formatv(pFormat, args); va_end (args); mpConsole->SetText(mpConsole->GetText() + nglString(_T("\n\n")) + buf); NGL_OUT(_T("%ls\n"), buf.GetChars()); }
void nuiSocket::DumpError(int err, const char* msg, ...) { if (!err) return; nglString error(strerror(errno)); if (msg) { nglString m; va_list args; va_start(args, msg); m.Formatv(msg, args); va_end(args); NGL_OUT(_T("[%s] Socket Error: %s\n"), m.GetChars(), error.GetChars()); } else NGL_OUT(_T("Socket Error: %s\n"), error.GetChars()); }
// first set : radio button with text inside nuiWidget* MainWindow::Tutorial_RadioButtons1() { NGL_OUT("MainWindow::Tutorial_RadioButtons1"); nuiHBox* pBox = new nuiHBox(0); for (int index = 0; index < 3; index++) // will create 3 radiobuttons, { nglString tmp; tmp.Format(_T("Radio %d"), index); nuiRadioButton* pRadioBut = new nuiRadioButton(tmp);// with text inside pRadioBut->SetObjectName(_T("MyButton")); pBox->AddCell(pRadioBut); pRadioBut->SetGroup(_T("radios")); // set the radio group for group behavior // will send an event in the ::OnRadioPressed receiver when the radiobutton is 'activated' mEventSink.Connect(pRadioBut->Activated, &MainWindow::OnRadioPressed, (void*)index); // index is given as a user parameter to recognise the button } NGL_OUT("MainWindow::Tutorial_RadioButtons1 OK"); return pBox; }
nuiWidget* MainWindow::Tutorial_ToggleButtons() { NGL_OUT("MainWindow::Tutorial_ToggleButtons"); nuiHBox* pBox = new nuiHBox(0); // a simple togglebutton nuiToggleButton* pBtn = new nuiToggleButton(_T("toggleButton")); pBtn->SetObjectName(_T("MyButton")); pBox->AddCell(pBtn); mEventSink.Connect(pBtn->ButtonPressed, &MainWindow::OnTogglePressed, (void*)TAG_BUTTON1); mEventSink.Connect(pBtn->ButtonDePressed, &MainWindow::OnTogglePressed, (void*)TAG_BUTTON2); // a togglebutton, with a "checkbox" look : leave the button without any child pBtn = new nuiToggleButton(); pBtn->SetObjectName(_T("MyButton")); pBox->AddCell(pBtn, nuiCenter); mEventSink.Connect(pBtn->ButtonPressed, &MainWindow::OnTogglePressed, (void*)TAG_BUTTON3); mEventSink.Connect(pBtn->ButtonDePressed, &MainWindow::OnTogglePressed, (void*)TAG_BUTTON4); NGL_OUT("MainWindow::Tutorial_ToggleButtons OK"); return pBox; }
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; }
void MainWindow::OnCreation() { NGL_OUT("MainWindow::OnCreation"); // create a vertical box for the layout nuiVBox* pMainBox = new nuiVBox(0); pMainBox->SetExpand(nuiExpandShrinkAndGrow); pMainBox->SetPosition(nuiFillVertical); AddChild(pMainBox); // create a label width background for information display nuiPane* pPane = new nuiPane(); pPane->SetBorder(20,20); pMainBox->AddCell(pPane, nuiFillHorizontal); mpLabel = new nuiLabel(); pPane->AddChild(mpLabel); pPane->SetUserHeight(40); nuiLabel* pLabel = new nuiLabel(_T("nuiButton:"), nuiFont::GetFont(16)); pMainBox->AddCell(pLabel, nuiLeft); pMainBox->AddCell(Tutorial_Buttons()); pLabel = new nuiLabel(_T("nuiToggleButton:"), nuiFont::GetFont(16)); pMainBox->AddCell(pLabel, nuiLeft); pMainBox->AddCell(Tutorial_ToggleButtons()); pLabel = new nuiLabel(_T("nuiRadioButton:"), nuiFont::GetFont(16)); pMainBox->AddCell(pLabel, nuiLeft); pMainBox->AddCell(Tutorial_RadioButtons1()); pLabel = new nuiLabel(_T("nuiRadioButton:"), nuiFont::GetFont(16)); pMainBox->AddCell(pLabel, nuiLeft); pMainBox->AddCell(Tutorial_RadioButtons2()); // make the mainbox's layout fill the entire user size (c.f. line #33) pMainBox->SetAllCellsExpand(nuiExpandShrinkAndGrow); NGL_OUT("MainWindow::OnCreation OK"); }
void nglLog::Output (const nglString& rText) const { #if DISABLE_LOG return; #endif if (mUseConsole) { NGL_OUT(rText); } OutputList::const_iterator out; for (out = mOutputList.begin(); out != mOutputList.end(); out++) (*out)->WriteText (rText); }