/// Copyright (c) 2009 Ruben Penalva. All rights reserved.
/// Redistribution and use in source and binary forms, with or without modification, 
/// are permitted provided that the following conditions are met:
///    1. Redistributions of source code must retain the above copyright notice, this 
///    list of conditions and the following disclaimer.
///    2. Redistributions in binary form must reproduce the above copyright notice,
///    this list of conditions and the following disclaimer in the documentation and/or
///    other materials provided with the distribution.
///    3. The name of the author may not be used to endorse or promote products derived
///    from this software without specific prior written permission.
///
/// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
/// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
/// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
/// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
/// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
/// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
/// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

/// @file Window.h
/// This source file is part of 2dRender LetterCDT Test.
/// The file holds the Window class interface.
/// @author Ruben Penalva (ruben.penalva@rpenalva.com)

#ifndef _WINDOW_H_
#define _WINDOW_H_

#include <string>
#include <vector>
#include "MenuEntry.h"

namespace GlutWrapper
{

class IRunner;
class IMouseListener;
class IKeyboardListener;
class IMenuListener;

class Window
{
public:
	/// Constructor
	/// It handles all the execution flow of the test.
	/// It creates the render window, runs the main loop,
	/// calls runner to execute the frame and creates the
	/// menu entries given by runner
	/// @param argc number of application arguments (for glut initialization)
	/// @param argv application arguments (for glut initialization)
	/// @param positionX render window position X coordinate
	/// @param positionY render window position Y coordinate
	/// @param width render window height
	/// @param windowName render window name
	/// @param runner test runner
	/// @param menuEntries entries of the right button menu
	/// @param menuListener listener of right button menu events
	/// @param idleRunning enable runs even when idle
	Window(int argc, char** argv, int positionX, int positionY, 
		   int width, int height, const std::string& windowName,
		   IRunner* runner, const std::vector<MenuEntry>& menuEntries,
		   IMenuListener* menuListener,
		   IMouseListener* mouseListener, 
		   IKeyboardListener* keyboardListener, bool idleRunning);

	/// Destructor
	~Window(void);

private:
	/// Test runner
	static IRunner* m_runner;

	/// Listener of right button menu events
	static IMenuListener* m_menuListener;

	/// Listener of keyboard events
	static IKeyboardListener* m_keyboardListener;

	/// @note hide copy constructor from interface user
	Window(const Window&);

	/// @note hide assignment operator from interface user
	Window& operator=(const Window&);

	/// @brief Initializes glut, glut callbacks and the listeners.
	/// @param argc number of application arguments (for glut initialization)
	/// @param argv application arguments (for glut initialization)
	/// @param positionX render window position X coordinate
	/// @param positionY render window position Y coordinate
	/// @param width render window height
	/// @param windowName render window name
	/// @param runner test runner
	/// @param menuEntries entries of the right button menu
	/// @param menuListener listener of right button menu events
	/// @param idleRunning enable runs even when idle
	void InitializeGlut(int argc, char** argv, int positionX, int positionY, 
						int width, int height, const std::string& windowName,
						IRunner* runner, const std::vector<MenuEntry>& menuEntries,
						IMenuListener* menuListener,
						IMouseListener* mouseListener, 
						IKeyboardListener* keyboardListener, bool idleRunning);

	/// @brief Callback of glut display event
	static void DisplayFunc(void);

	/// @brief Callback of glut reshape event
	/// @param width new render window
	/// @param height new render window
	static void ReshapeFunc(int width, int height);

	/// @brief Callback of glut menu event
	/// @param option the event option
	static void ProcessMenuEvents(int option);

	/// @brief Callback of keyboard events
	/// @param key key code
	/// @param x 
	/// @param y
	static void ProcessNormalKeys(unsigned char key, int x, int y);

};

}

#endif