value lime_window_close (value window) { Window* targetWindow = (Window*)(intptr_t)val_float (window); targetWindow->Close (); return alloc_null (); }
int main(int argc, char** argv) { int wndFlags = Window::WF_DEFAULT; // If the user passes -fullscreen as an argument, then // a fullscreen window will be created. if (argc > 1) { if (strcmp(argv[1], "-fullscreen") == 0) { wndFlags = Window::WF_FULLSCREEN; } } // Create a new window instance Window wnd; // Open the window if (!wnd.Open(800, 600, L"Hello, World!", wndFlags)) { printf("Error - Unable to open the window!\n"); exit(-1); } // By default the window is placed in the center of the screen. // Move it to (100, 100). wnd.setPosition(100, 100); // Until the user closes the window while (!wnd.isCloseRequested()) { // Poll window events wnd.pollEvents(); } // Close the window. This line is not required, because the // window is automatically close when the wnd instance is destroyed. wnd.Close(); return 0; }
// static void Window::CloseSecondaryWidget(Widget* widget) { if(!widget) { return; } // Close widget if it's identified as a secondary window. Window* window = widget->GetWindow(); if(window) { if(!window->IsAppWindow()) { window->Close(); } } else { // If it's not a Window, then close it anyway since it probably is // secondary. widget->Close(); } }
int main() { // Init GLFW glfwInit(); // Create a GLFWwindow object that we can use for GLFW's functions Window window = Window(WIDTH, HEIGHT, TITLE); window.DefineViewport(); //glfwSetInputMode(window.getWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); /// ^(Maybe use this later) // Callback functions glfwSetKeyCallback(window.getWindowPtr() , key_callback); // Init GLEW glewExperimental = GL_TRUE; glewInit(); // Enable alpha channel transparency glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Load and compile shaders to a program Shader ShaderProgram = Shader("../deps/shaders/shadervert.vs", "../deps/shaders/shaderfrag.fs"); // Load explosion graphics extern_Explosion.Init(ShaderProgram.GetProgramID()); // Load texture/Game objects Texture2D texture_background1 = Texture2D("../deps/textures/backgroundSpace_01.1.png", PNG_RGB); SpriteMap Background = SpriteMap(texture_background1, 1.0f, 1.0f, glm::vec3(0.0f, 0.0f, 0.0f), 1.0f, BACKGROUND); Player PlayerShip; PlayerShip.Init(moveSpeed); Enemy Enemies; Enemies.Init(); // Projection matrix: ortho for 2D glm::mat4 proj = glm::ortho(0, window.getWidth(), 0, window.getHeight()); // Game loop while (!window.ShouldClose()) { double startFrame = glfwGetTime(); ///< for FPS limiting // Check if any events have been activiated and call callback function (via GLFW) glfwPollEvents(); // Clear the colorbuffer glClearColor(0.6f, 0.8f, 0.8f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Drawing */ ShaderProgram.Use(); // Background position and drawing calculations - just identity matrix glm::mat4 model; GLint modelLoc = glGetUniformLocation(ShaderProgram.GetProgramID(), "model"); glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); Background.BackgroundScroll(scrollSpeed); Background.Draw(); Collision::EnemyHit(&PlayerShip, &Enemies); Collision::PlayerHit(&PlayerShip, &Enemies); Collision::ShipsCollide(&PlayerShip, &Enemies); PlayerShip.Move(keys); PlayerShip.AddShots(keys); PlayerShip.Draw(ShaderProgram.GetProgramID()); Enemies.Move(); Enemies.Shoot(PlayerShip.GetPosition()); Enemies.Draw(ShaderProgram.GetProgramID()); extern_Explosion.Draw(); // FPS Calculation/Limiting float fps = CalculateFPS(); static int printFPS = 0; if (printFPS == 100) { Enemies.Add(EN_0, PlayerShip.GetPosition()); Enemies.Add(EN_1, PlayerShip.GetPosition()); std::cout << fps << std::endl; printFPS = 0; } else { printFPS++; } LimitFPS(FPS, startFrame); if (PlayerShip.GetLives() <= 0) { window.Close(); } // Swap the screen buffers window.SwapBuffers(); } Background.Delete(); PlayerShip.Delete(); Enemies.DeleteAll(); extern_Explosion.DeleteAll(); // Close GLFW glfwTerminate(); return 0; }
void View::CloseAllWindows( void ) { for ( Window *w = static_cast<Window *>(windows.Head()); w && !w->Closed(); w = static_cast<Window *>(w->Next()) ) w->Close(); Refresh(); }
int main(int argc, char *argv[]) #endif { LOG_DEBUG("Opening window ..."); Window window = Window("Snowflake Sandbox", VideoMode(1280, 768)); Color clearColor = Color(50, 80, 80, 255); GLfloat vertexBufferData[] = { // Front face -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, // Back face -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, // Top face -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, // Bottom face -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, -1.0, 1.0, // Right face 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, // Left face -1.0, -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0 }; GLfloat colorBufferData[] = { 0.583f, 0.771f, 0.014f, 0.609f, 0.115f, 0.436f, 0.327f, 0.483f, 0.844f, 0.822f, 0.569f, 0.201f, 0.435f, 0.602f, 0.223f, 0.310f, 0.747f, 0.185f, 0.597f, 0.770f, 0.761f, 0.559f, 0.436f, 0.730f, 0.359f, 0.583f, 0.152f, 0.483f, 0.596f, 0.789f, 0.559f, 0.861f, 0.639f, 0.195f, 0.548f, 0.859f, 0.014f, 0.184f, 0.576f, 0.771f, 0.328f, 0.970f, 0.406f, 0.615f, 0.116f, 0.676f, 0.977f, 0.133f, 0.971f, 0.572f, 0.833f, 0.140f, 0.616f, 0.489f, 0.997f, 0.513f, 0.064f, 0.945f, 0.719f, 0.592f, 0.543f, 0.021f, 0.978f, 0.279f, 0.317f, 0.505f, 0.167f, 0.620f, 0.077f, 0.347f, 0.857f, 0.137f, 0.055f, 0.953f, 0.042f, 0.714f, 0.505f, 0.345f, 0.783f, 0.290f, 0.734f, 0.722f, 0.645f, 0.174f, 0.302f, 0.455f, 0.848f, 0.225f, 0.587f, 0.040f, 0.517f, 0.713f, 0.338f, 0.053f, 0.959f, 0.120f, 0.393f, 0.621f, 0.362f, 0.673f, 0.211f, 0.457f, 0.820f, 0.883f, 0.371f, 0.982f, 0.099f, 0.879f }; GLushort indicesData[] = { 0, 1, 2, 0, 2, 3, // front 4, 5, 6, 4, 6, 7, // back 8, 9, 10, 8, 10, 11, // top 12, 13, 14, 12, 14, 15, // bottom 16, 17, 18, 16, 18, 19, // right 20, 21, 22, 20, 22, 23 // left }; VertexArray cube, cube2; IndexBuffer ibo(indicesData, std::end(indicesData) - std::begin(indicesData)); cube.AddBuffer(sfnew Buffer(vertexBufferData, sizeof(vertexBufferData), 3), 0); cube.AddBuffer(sfnew Buffer(colorBufferData, sizeof(colorBufferData), 3), 1); cube2.AddBuffer(sfnew Buffer(vertexBufferData, sizeof(vertexBufferData), 3), 0); cube2.AddBuffer(sfnew Buffer(colorBufferData, sizeof(colorBufferData), 3), 1); Matrix4 projection = Matrix4::Perspective(100.0f, window.GetSize().X / window.GetSize().Y, 0.1f, 100.f); Matrix4 view = Matrix4::LookAt(Vector3(4, 3, 3), Vector3(0, 0, 0), Vector3(0, 0.8f, 0)); Matrix4 model = Matrix4(1.0f); Matrix4 mvp = projection * view * model; Shader shader = Shader("tri_vertex.glsl", "tri_fragment.glsl"); shader.Enable(); while (!window.ShouldClose()) { window.Clear(clearColor); // Render here cube.Bind(); ibo.Bind(); model = Matrix4::Translation(Vector3(0, 0, 0)); mvp = projection * view * model; shader.SetUniformMat4("MVP", mvp); glDrawElements(GL_TRIANGLES, ibo.GetCount(), GL_UNSIGNED_SHORT, 0); ibo.Bind(); cube.Unbind(); cube2.Bind(); ibo.Bind(); model = Matrix4::Translation(Vector3(4, 0, 0)); mvp = projection * view * model; shader.SetUniformMat4("MVP", mvp); glDrawElements(GL_TRIANGLES, ibo.GetCount(), GL_UNSIGNED_SHORT, 0); ibo.Bind(); cube2.Unbind(); window.Display(); window.Update(); } window.Close(); #if _DEBUG LOG_DEBUG("PAUSING NOW!"); system("PAUSE"); #endif return EXIT_SUCCESS; }
void Window::WindowClosed(GLFWwindow* Handle) { Window* BakgeWindow = (Window*)glfwGetWindowUserPointer(Handle); BakgeWindow->Close(); }
// Methods used by instantiator/creator and/or self OP_BOOLEAN TransferManagerDownloadCallback::Execute() { OP_STATUS status; BOOL done = FALSE; if (!cancelled) { if (called) { switch (download_action_mode) { case DOWNLOAD_UNDECIDED: // TODO: This should not be possible, need to test...... // Use this to throw things back at document manager done = TRUE; break; case DOWNLOAD_ABORT: if (keep_loading) { if (document_manager) document_manager->SetLoadStatus(WAIT_FOR_LOADING_FINISHED); } else { if (document_manager) document_manager->StopLoading(FALSE); if (!download_url.GetRep()->GetUsedCount()) // These two lines belong in the url module download_url.Unload(); // rfz 20071028 } EnableWindowClose(); done = TRUE; break; case DOWNLOAD_SAVE: case DOWNLOAD_RUN: if (!dont_add_to_transfers) { BOOL show_transfer = TRUE; if (download_context) show_transfer = download_context->IsShownDownload(); TransferItem* newitem = 0; // Put the download object into TransferManager status = ((TransferManager*)g_transferManager)->AddTransferItem(download_url, download_filename.CStr(), OpTransferItem::ACTION_UNKNOWN, FALSE, 0, TransferItem::TRANSFERTYPE_DOWNLOAD, NULL, NULL, FALSE, show_transfer, m_privacy_mode, &newitem); if (status == OpStatus::OK) { if (download_context && download_context->GetTransferListener()) newitem->SetTransferListener(download_context->GetTransferListener()); if (download_action_mode == DOWNLOAD_SAVE) newitem->SetAction(OpTransferItem::ACTION_SAVE); else if (download_action_mode == DOWNLOAD_RUN) newitem->SetAction(OpTransferItem::ACTION_RUN_WHEN_FINISHED); newitem->SetViewer(viewer); if (need_copy_when_downloaded) newitem->SetCopyWhenDownloaded(download_filename); MessageHandler *oldHandler = download_url.GetFirstMessageHandler(); // Check if this URL is already being downloaded to some file // (the same file or another file - who knows?). The Opera core // doesn't handle concurrent downloading of the same URL properly. // So just give up. // // The result will be that the transfer already in progress completes // without problems, while the new transfer that was attempted added, // will hang (the progress bar in the window that triggered the transfer // will stay there until the user aborts it somehow). MessageHandler *currentHandler = oldHandler; BOOL transfer_in_progress = FALSE; while (currentHandler && !transfer_in_progress) { if (currentHandler == g_main_message_handler) transfer_in_progress = TRUE; else currentHandler = static_cast<MessageHandler *>(currentHandler->Suc()); } if (!transfer_in_progress) { FramesDocument *doc = document_manager ? document_manager->GetCurrentDoc() : NULL; URLStatus ust = download_url.Status(FALSE); switch (ust) { case URL_UNLOADED: download_url.Load(g_main_message_handler, doc ? doc->GetURL() : URL()); currentHandler = g_main_message_handler; break; case URL_LOADING_ABORTED: download_url.ResumeLoad(g_main_message_handler, doc ? doc->GetURL() : URL()); currentHandler = g_main_message_handler; break; default: if ((ust == URL_LOADED || ust == URL_LOADING_FAILURE) && is_download_to && !download_to_started) { // Fix for DSK-232055 - the best we can do is to reload URL ref = download_url.GetAttribute(URL::KReferrerURL); download_url.SetAttribute(URL::KReloadSameTarget, TRUE); download_url.Reload(g_main_message_handler, ref, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE); currentHandler = g_main_message_handler; } else { if (oldHandler && !keep_loading) { download_url.ChangeMessageHandler(oldHandler, g_main_message_handler); currentHandler = g_main_message_handler; } else currentHandler = oldHandler; } } } // currentHandler is NULL when download_url.Status(FALSE) equals URL_LOADING_FAILED, or shall we set it to g_main_message_handler anyway? if (currentHandler) newitem->SetCallbacks(currentHandler, download_url.Id(TRUE)); } } if (download_action_mode == DOWNLOAD_RUN) { if ( document_manager && download_url.Status(FALSE) != URL_UNLOADED && download_url.Status(TRUE) != URL_LOADING) { // The loading has already finished. We have to trigger the action // manually by using HandleAllLoaded() [espen] // InitiateTransfer() above destroys filename // doc_man->SetCurrentURL(saved_url); if( viewer.GetAction() == VIEWER_APPLICATION || viewer.GetAction() == VIEWER_PASS_URL) { document_manager->SetAction(VIEWER_APPLICATION); document_manager->SetApplication(viewer.GetApplicationToOpenWith()); } else if(viewer.GetAction() == VIEWER_REG_APPLICATION) { document_manager->SetAction(VIEWER_REG_APPLICATION); } // Restore // doc_man->SetCurrentURL(GetUrl()); } } if (dont_add_to_transfers) { if (download_context && download_context->GetTransferListener()) download_context->GetTransferListener()->OnSavedFromCacheDone(download_filename); } done = TRUE; break; } // Here we clean up in the context of document manager if (document_manager && !keep_loading) document_manager->StopLoading(FALSE); //the window is not handling the loading anymore if (document_manager && download_url.Status(TRUE) != URL_LOADING) document_manager->HandleAllLoaded(download_url.Id(TRUE)); EnableWindowClose(); } else { #ifdef WEB_TURBO_MODE // Downloads should not use Turbo. NB! This WILL generate a second request for the same resource (this time without using the Turbo proxy) if (download_url.GetAttribute(URL::KUsesTurbo) && !download_url.GetAttribute(URL::KTurboBypassed) && #ifdef _BITTORRENT_SUPPORT_ download_url.ContentType() != URL_P2P_BITTORRENT && #endif // _BITTORRENT_SUPPORT_ document_manager) { URLStatus ustat = (URLStatus)download_url.GetAttribute(URL::KLoadStatus, URL::KFollowRedirect); if (ustat == URL_LOADING) document_manager->StopLoading(FALSE); const OpStringC8 url_str = download_url.GetAttribute(URL::KName_With_Fragment_Username_Password_NOT_FOR_UI, URL::KNoRedirect); download_url = g_url_api->GetURL(url_str.CStr()); document_manager->SetCurrentURL(download_url, TRUE); } #endif // WEB_TURBO_MODE delayed = TRUE; } } if (done) { Window* win = document_manager ? document_manager->GetWindow():NULL; TryDelete(); //if the window is Not intiated by the user and this is the first url the window loads, close it //since the data is handled elsewhere. if (win && win->GetOpenerWindow() && win->GetHistoryLen() == 0 && win->CanClose()) win->Close(); return OpBoolean::IS_TRUE; // Signifying that we have done a transition through a download initiation } else { return OpBoolean::IS_FALSE; // Signifying that we will back here before we are done } }
int main(){ try{ ILogger::Init(); Settings::Call().Parse(); ResourceManager::Call().AddPath("Data/shaders", "Shader"); ResourceManager::Call().AddPath("Data/textures", "Image"); { Window myWindow; Image Crate; Texture CrateTexture; Text FPSText, MousePosText; Clock FrameClock, FpsClock; Input myInput; myInput.Init(myWindow); Renderer& myRenderer = Renderer::Call(); myRenderer.Init(myWindow); Crate.LoadFromFile("crate.jpg"); CrateTexture.LoadFromImage(Crate); Light l; l.SetPosition(Vector3F(1,3,1.5)); l.SetDiffuse(Color(1.f,1.f,1.f)); l.SetRange(8); Shader ColorShader; ColorShader.Compile("shaderColor.vs", "shaderColor.fs"); ColorShader.Bind(); ColorShader.SendColor("ambientColor", myRenderer.GetSpecifications().mAmbientColor); ColorShader.SendFloat("constantAtt", l.GetAttenuationConstant()); ColorShader.SendFloat("linearAtt", l.GetAttenuationLinear()); ColorShader.SendFloat("quadraticAtt", l.GetAttenuationQuadratic()); ColorShader.SendFloat("range", l.GetRange()); ColorShader.SendVector3("lightPosition", l.GetPosition()); ColorShader.SendColor("lightColor", l.GetDiffuse()); ColorShader.UnBind(); Object obj1; obj1.MakeCube("cube", ColorShader); obj1.GetMaterial().mAmbient = Color(0.f, 0.08f, 0.08f); obj1.GetMaterial().mDiffuse = Color(0.f, 0.8f, 0.8f); obj1.GetMaterial().mSpecular = Color(0.0f, 0.5f, 0.5f); obj1.GetMaterial().mShininess = 50.f; Camera cam; cam.LookAt(Vector3F(0.5f,0,1), Vector3F(-2.5f,2,4)); FPSText.SetSize(12); FPSText.SetPosition(10,10); MousePosText.SetSize(12); MousePosText.SetPosition(10,22); while(myWindow.IsOpened()){ ElapsedTime = FrameClock.GetElapsedTime(); FrameClock.Reset(); if(FpsClock.GetElapsedTime() > 1.f){ FPSText.SetText(String(1.f/ElapsedTime)); FpsClock.Reset(); } while(myInput.GetEvent()){ if(myInput.GetEventType() == sf::Event::Closed) myWindow.Close(); if(myInput.IsKeyHit(Space)) if(!paused){ paused = true; FrameClock.Pause(); }else{ paused = false; FrameClock.Resume(); } } MousePosText.SetText(String("X : ")+myInput.GetMouseX()+" Y : "+myInput.GetMouseY()); MousePosText.Draw(); FPSText.Draw(); obj1.Draw(); myRenderer.BeginScene(myRenderer.GetSpecifications().mAmbientColor); myRenderer.Render(); myRenderer.EndScene(); } } }catch(Exception e){ std::cout << e.what() << std::endl; system("PAUSE"); } Renderer::Kill(); ResourceManager::Kill(); Settings::Kill(); ILogger::Kill(); #ifdef _DEBUG MemoryManager::Kill(); #endif return 0; }
void lime_window_close (value window) { Window* targetWindow = (Window*)val_data (window); targetWindow->Close (); }