/*
 * Copyright 2014-2015 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.kotcrab.vis.editor.module.editor;

import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;

/**
 * Module controlling UI debug mode which can be enabled by pressing F12 key.
 * @author Kotcrab
 */
public class UIDebugControllerModule extends EditorModule {
	private StatusBarModule statusBar;
	private GlobalInputModule inputModule;

	private Stage stage;

	private boolean debugEnabled;

	private InputListener inputListener = new InputListener() {
		@Override
		public boolean keyDown (InputEvent event, int keycode) {
			if (keycode == Keys.F12) {
				debugEnabled = !debugEnabled;
				stage.setDebugAll(debugEnabled);

				if (debugEnabled)
					statusBar.setText("UI debug mode was enabled! (press F12 to disable)");
				else
					statusBar.setText("UI debug mode was disabled!");

				return true;
			}

			return false;
		}
	};

	@Override
	public void init () {
		inputModule.addListener(inputListener);
	}

	@Override
	public void dispose () {
		inputModule.removeListener(inputListener);
	}
}

@@ -718,26 +718,17 @@
 scene2d.
-InputEvent
+*
 ;%0Aimport
@@ -760,29 +760,30 @@
 scene2d.
-InputListener
+ui.WidgetGroup
 ;%0Aimport
@@ -815,21 +815,28 @@
 scene2d.
-Stage
+utils.Layout
 ;%0A%0A/**%0A 
@@ -1259,16 +1259,261 @@
 code) %7B%0A
+%09%09%09if (keycode == Keys.F11) %7B%0A%09%09%09%09for (Actor actor : stage.getRoot().getChildren()) %7B%0A%09%09%09%09%09if (actor instanceof WidgetGroup) %7B%0A%09%09%09%09%09%09invalidateRecursively((WidgetGroup) actor);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%0A%09%09%09%09statusBar.setText(%22Invalidated UI layout%22);%0A%09%09%09%7D%0A%0A
 %09%09%09if (k
@@ -1818,13 +1818,303 @@
 %09%09%7D%0A
-
 %09%7D;%0A%0A
+%09private void invalidateRecursively (WidgetGroup group) %7B%0A%09%09group.invalidate();%0A%0A%09%09for (Actor actor : group.getChildren()) %7B%0A%09%09%09if (actor instanceof WidgetGroup)%0A%09%09%09%09invalidateRecursively((WidgetGroup) actor);%0A%09%09%09else if (actor instanceof Layout)%0A%09%09%09%09((Layout) actor).invalidate();%0A%09%09%7D%0A%09%7D%0A%0A
 %09@Ov

Add debug full layout invalidate