/*
	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 GUIWIDGET_H
#define GUIWIDGET_H

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

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

//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################
//
//
// Class Name:   GuiWidget
// Purpose:      Provides a base class for all GUI widgets in the game, be they
//               buttons, or lists or just plain labels.
//
//
//##############################################################################
//##############################################################################
//##############################################################################
//##############################################################################

class GuiWidget : public GLWindowEventListener
{

 public:

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

        // Default constructor: initialises some common widget settings

        GuiWidget();

        // Virtual destructor for widgets: does not have to be implemented

        virtual ~GuiWidget(){;}

        // Attribute setting

        void setColor           ( float r , float g , float b );
        void setSize            ( int w , int h );
        void setPosition        ( int x , int y );
        void setVisible         ( bool visible );
        void setEnabled         ( bool enabled );
        void setFocus           ( bool hasFocus );
        void setEventListener   ( GLWindowEventListener * eventListener );

        // Attribute retrieval

        inline float getColorR()    { return baseColor_r ; }
        inline float getColorG()    { return baseColor_g ; }
        inline float getColorB()    { return baseColor_b ; }

        inline int getSizeX()       { return size_x ; }
        inline int getSizeY()       { return size_y ; }

        inline int getPositionX()   { return position_x ; }
        inline int getPositionY()   { return position_y ; }

        inline bool isVisible()     { return visible;  }
        inline bool isEnabled()     { return enabled;  }
        inline bool getFocus()      { return hasFocus; }

        inline GLWindowEventListener * getEventListener()  { return eventListener; }
        
        // No unreferenced param warning
        
        #pragma warning(disable:4100)                 

        // Methods which should be overriden in derived classes to give widgets functionality:

        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 windowRedrawing    (){;}

        // New events specific to GUI screens. Should be over-ridden in derived classes

        virtual void gainedFocus ( int mouseX , int mouseY ){;}
        virtual void lostFocus   (){;}

        // Methods which are inherited from GLEvent listener but are not used

        void keyboardPressed    ( GLWindow::KeyboardKey key ){;}
        void keyboardReleased   ( GLWindow::KeyboardKey key ){;}
        void windowResized(){;}
        void windowClosing(){;}
        void windowClosed(){;}
        
		// Restore this to normal
            
		#pragma warning(default:4100)        
		
		// Get the parent of this widget
		
		GuiWidget * getParent() { return parent; }
		
		// Set the parent of the widget. The reference is weak so use with care.
		
		void setParent(GuiWidget * newParent) { this->parent = newParent; }

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

 protected:

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

        float baseColor_r;      // base color of the widget
        float baseColor_g;
        float baseColor_b;

        int size_x;             // size of the widget
        int size_y;

        int position_x;         // position of the widget
        int position_y;

        bool  visible;          // is the widget visible ?
        bool  enabled;          // is the widget allowed to send events to its event listener ?
        bool  hasFocus;         // is the mouse currently over the selected widget ?

        GLWindowEventListener * eventListener;    // widget event listener
        
        GuiWidget * parent;		// parent of the window if there is any - null otherwise.

}; // end of: class GuiWidget{}

#endif // end of: ifndef GUIWIDGET_H
