/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.tests.gwt;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.tests.utils.GdxTest;

public class GwtWindowModeTest extends GdxTest {
	private Stage stage;
	boolean isWindowed;
	TextButton changeModeButton;
	private final String windowedInstructions = "click for Full screen Mode";
	private final String fullScreenInstructions = "click for window Mode";

	public void create () {
		stage = new Stage();
		isWindowed = true;
		Gdx.input.setInputProcessor(stage);
		Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));

		changeModeButton = new TextButton(windowedInstructions, skin);
		changeModeButton.setSize(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
		changeModeButton.setPosition(Gdx.graphics.getWidth() / 4, Gdx.graphics.getHeight() / 4);
		stage.addActor(changeModeButton);

		changeModeButton.addListener(new ClickListener() {
			@Override
			public void clicked (InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				if (isWindowed) {
					isWindowed = false;
					changeModeButton.setText(fullScreenInstructions);
					Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
				} else {
					isWindowed = true;
					changeModeButton.setText(windowedInstructions);
					Gdx.graphics.setWindowedMode(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
				}
			}
		});
	}

	public void render () {
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		stage.act(Gdx.graphics.getDeltaTime());
		stage.draw();
	}

	public void resize (int width, int height) {
		stage.getViewport().update(width, height, true);
	}

	public void dispose () {
		stage.dispose();
	}
}

@@ -112,17 +112,16 @@
 file.%0A *
- 
 %0A * Lice
@@ -293,17 +293,16 @@
 se at%0A *
- 
 %0A *   ht
@@ -344,17 +344,16 @@
 E-2.0%0A *
- 
 %0A * Unle
@@ -1426,16 +1426,99 @@
 w Mode%22;
+%0A%09private final String notSupported = %22Changing the display mode is not supported%22;
 %0A%0A%09publi
@@ -2123,16 +2123,69 @@
  x, y);%0A
+%09%09%09%09if (Gdx.graphics.supportsDisplayModeChange()) %7B%0A%09
 %09%09%09%09if (
@@ -2194,24 +2194,25 @@
 Windowed) %7B%0A
+%09
 %09%09%09%09%09isWindo
@@ -2224,16 +2224,17 @@
  false;%0A
+%09
 %09%09%09%09%09cha
@@ -2272,32 +2272,33 @@
 nInstructions);%0A
+%09
 %09%09%09%09%09Gdx.graphic
@@ -2353,16 +2353,17 @@
 ));%0A%09%09%09%09
+%09
 %7D else %7B
@@ -2363,16 +2363,17 @@
  else %7B%0A
+%09
 %09%09%09%09%09isW
@@ -2388,16 +2388,17 @@
 = true;%0A
+%09
 %09%09%09%09%09cha
@@ -2438,24 +2438,25 @@
 tructions);%0A
+%09
 %09%09%09%09%09Gdx.gra
@@ -2525,24 +2525,89 @@
 tHeight());%0A
+%09%09%09%09%09%7D%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09changeModeButton.setText(notSupported);%0A
 %09%09%09%09%7D%0A%09%09%09%7D%0A%09

add supportsDisplayModeChange check to GwtWindowModeTest