/*
	Rogue Trader.
	Copyright (c) 2007, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''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 DARRAGH COY 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.
*/

#ifndef GUISCREEN_H
#define GUISCREEN_H

//##############################################################################
// C Includes
//##############################################################################

#include <Windows.h>
#include <gl/gl.h>

//##############################################################################
// Forward references
//##############################################################################

class GuiWidget;
class GuiPanel;
class GuiButton;
class GuiLabel;
class GLTextureManager;
class SoundManager;
class SoundSystem;

//##############################################################################
// C++ Includes: cant forward reference these because the compiler complains
//##############################################################################

#include "GLWindow.h"
#include "GLWindowEventListener.h"

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   GuiScreen
// Purpose:      Provides a base class for all GUI screens, along with some common
//               functionality. A GUI screen also listens for events coming from
//               the application window.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class GuiScreen : public GLWindowEventListener
{

 public:

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // Base class constructor: does some important initialisation for the GUI screen

        GuiScreen();

        // Base class destructor: deletes all widgets from the GUI screen

        virtual ~GuiScreen();

        // Trys to add a widget to the GUI screen. Widget memory is managed by the GUI screen from here on in.
        // If the add is unsuccessful the widget is deleted.

        void addWidget ( GuiWidget * widget );

        // Trys to remove a widget from the GUI screen. Deletes it also if found.

        void removeWidget ( GuiWidget * widget );

        // Begin running the GUI screen. Only return once the GUI screen has been exited.

        void run();

        // Cease running the gui screen

        void exit();

        // Show a dialog box with an ok button:

        static void showMessageDialog
        (
            const char * title,
            const char * message
        );

        // Show a question box with a yes and no button: returns true on yes and no on false

        static bool showQuestionDialog
        (
            const char * title,
            const char * message,
            const char * question
        );

        // Shows an input box which receives textual input. Input lenght is restricted to 32 chars in total.
        // Returns a pointer to the string which was input. This string should NOT be modified.
        // This function does not allow numeric input either.

        static const char * showInputDialog
        (
            const char * title,
            const char * prompt
        );

        // Forces a refresh of the gui screen:

        inline void redraw(){ windowRedrawing(); }

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

 protected:

        //----------------------------------------------------------------------
        // Variables
        //----------------------------------------------------------------------

        float backgroundColor_r;    // color of the GUI background: in normalised floating point format
        float backgroundColor_g;
        float backgroundColor_b;

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

 private:

        //----------------------------------------------------------------------
        // Constants
        //----------------------------------------------------------------------

        // Maximum number of widgets a GUI screen can support

        static const unsigned MAX_WIDGETS = 128;

        //----------------------------------------------------------------------
        // Functions
        //----------------------------------------------------------------------

        // These event handling function are private and cannot be over-ridden by derived classes

        void mouseMoved         ( int x , int y );
        void mousePressed       ( int x , int y , GLWindow::MouseButton button );
        void mouseReleased      ( int x , int y , GLWindow::MouseButton button );

        void keyboardPressed    ( GLWindow::KeyboardKey key );
        void keyboardReleased   ( GLWindow::KeyboardKey key );

        void windowResized    ();
        void windowClosing    ();
        void windowClosed     ();
        void windowRedrawing  ();

        //----------------------------------------------------------------------
        // Variables
        //----------------------------------------------------------------------

        // Continue running the GUI ? 'exit' sets this to false

        bool continueRunning;

        // The array of pointers to widgets

        GuiWidget * widgets[MAX_WIDGETS];

}; // end of: class GuiScreen{}

//##############################################################################
// C++ includes
//##############################################################################

#include "GuiWidget.h"
#include "GuiPanel.h"
#include "GuiButton.h"
#include "GuiLabel.h"
#include "GLTextureManager.h"
#include "SoundManager.h"
#include "SoundSystem.h"

#endif // end of: ifndef GUISCREEN_H
