Jump to content

Recommended Posts

Posted

I want to be able to toggle between diffren windows styles (FullScreen and Resizable).

 

For all examples I have created I have used a new project and only added the if (window->KeyHit(Key::R)) block and I create the window in App::Start() with Leadwerks::Window::Create("test", 0, 0, 1024, 768, Leadwerks::Window::Resizable);

 

Example one. I can toggle from windowed mode to full screen mode but not back to windowed mode with this code:

 

 

bool App::Loop()
{
   //Close the window to end the program
   if (window->Closed()) return false;

   //Press escape to end freelook mode
   if (window->KeyHit(Key::Escape))
   {
       if (!freelookmode) return false;
       freelookmode=false;
       window->ShowMouse();
   }

   if (freelookmode)
   {
       //Keyboard movement
       float strafe = (window->KeyDown(Key:) - window->KeyDown(Key::A))*Leadwerks::Time::GetSpeed() * 0.05;
       float move = (window->KeyDown(Key::W) - window->KeyDown(Key::S))*Leadwerks::Time::GetSpeed() * 0.05;
       camera->Move(strafe,0,move);

       //Get the mouse movement
       float sx = context->GetWidth()/2;
       float sy = context->GetHeight()/2;
       Vec3 mouseposition = window->GetMousePosition();
       float dx = mouseposition.x - sx;
       float dy = mouseposition.y - sy;

       //Adjust and set the camera rotation
       camerarotation.x += dy / 10.0;
       camerarotation.y += dx / 10.0;
       camera->SetRotation(camerarotation);

       //Move the mouse to the center of the screen
       window->SetMousePosition(sx,sy);
   }

   if (window->KeyHit(Key::R)) {
    if (window->style == Leadwerks::Window::FullScreen) {
	  System::Print("Go Resizable");
      window->Release();
	  window = Leadwerks::Window::Create("test", 0, 0, 800, 600, Leadwerks::Window::Resizable);
    } else {
	   System::Print("Go FullScreen");
	   window->Release();
	   window = Leadwerks::Window::Create("test", 0, 0, 1920, 1200, Leadwerks::Window::FullScreen);
    }
    //Create a context
       context = Context::Create(window);
    window->HideMouse();
    window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2);
   }

   Leadwerks::Time::Update();
   world->Update();
   world->Render();
   context->Sync(false);

   return true;
}

 

So when I hit R i get in to full screen but when I hit R again I do not get back to windowed mode. When I hit ESC twice I get back my desktop by exiting the application.

 

Example 2. So to test what happens behind the sceens I changed the if (window->KeyHit(Key::R)) block to this:

 

   if (window->KeyHit(Key::R)) {
    if (window->style == Leadwerks::Window::Titlebar) {
	    System::Print("Go Resizable");
	    window->Release();
	    window = Leadwerks::Window::Create("test", 0, 0, 1024, 768, Leadwerks::Window::Resizable);
    } else {
	    System::Print("Go other size");
	    window->Release();
	    window = Leadwerks::Window::Create("test", 0, 0, 800, 600, Leadwerks::Window::Titlebar);
    }
    //Create a context
    context = Context::Create(window);
    window->HideMouse();
    window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2);
   }

 

Everytime I hit R I get a new window but the old window is not removed (so I get a large amount os windows).

 

What am I doing wrong? or is this a bug?

Posted

Sorry for the late answer but I have been busy with my kids

 

I can confirm that window->takeownership work. I have changed my code to this and I can now create a new window and get the old window destroyed:

 

   if (window->KeyHit(Key::R)) {
    window->takeownership = true;
    if (window->style == Leadwerks::Window::FullScreen) {
	    System::Print("Go Resizable");
	    window->Release();
	    window = Leadwerks::Window::Create("test", 0, 0, 1024, 768, Leadwerks::Window::Resizable);
    } else {
	    System::Print("Go FullScreen");
	    window->Release();
	    window = Leadwerks::Window::Create("test", 0, 0, 1920, 1200, Leadwerks::Window::FullScreen);
    }
    //Create a context
    context = Context::Create(window);
    window->HideMouse();
    window->SetMousePosition(context->GetWidth()/2,context->GetHeight()/2);
}

 

Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...