// ---------------------------------------------------------------------------
// 
//   Lily Engine alpha
// 
//   Copyright (c) 2010 Clifford Jolly
//     http://cliffjolly.com
//     cliff@cliffjolly.com
// 
// ---------------------------------------------------------------------------
// 
//   This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//  
//   This program is distributed in the hope that it will be useful, but
//   WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//   General Public License for more details.
// 
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
//   USA
// -------------------------- END HEADER -------------------------------------

#ifndef WIDGET_SCROLLABLE
#define WIDGET_SCROLLABLE

#include "widget.h"
#include "widgetsingleparent.h"

/// WidgetScrollable contains a single widget and can shrink smaller
/// than that widget, showing only a region of it. The drawing offset
/// and mouse event offset of the contained widget can be set to move
/// the view around. A scrollable area, but very basic and with no
/// scrollbars. (Add these as part of a bigger widget.)
LUA_WRAP class WidgetScrollable : public WidgetSingleParent {
	public:

		// Things unique to WidgetScrollable...

		/// Get the largest offset for the X axis. Minimum is always 0.
		LUA_WRAP float getMaxOffsetX(void);
		
		/// Get the largest offset for the Y axis. Minimum is always 0.
		LUA_WRAP float getMaxOffsetY(void);
		
		/// Set the X scrolling amount. Gets clamped internally.
		LUA_WRAP void setOffsetX(float offset);
		
		/// Set the Y scrolling amount. Gets clamped internally.
		LUA_WRAP void setOffsetY(float offset);
		
		/// Get the X scrolling amount.
		LUA_WRAP float getOffsetX(void);
		
		/// Get the Y scrolling amount.
		LUA_WRAP float getOffsetY(void);

		/// Get whether or not this widget scrolls up/down.
		LUA_WRAP bool getScrollVertically(void);
		
		/// Get whether or not this widget scrolls left/right.
		LUA_WRAP bool getScrollHorizontally(void);
		
		/// Set whether or not this widget scrolls up/down.
		LUA_WRAP void setScrollVertically(bool b);
		
		/// Set whether or not this widget scrolls left/right.
		LUA_WRAP void setScrollHorizontally(bool b);

		/// Hook up a scrollbar Widget to this for the vertical axis.
		LUA_WRAP void setVerticalScrollBar(Widget *bar);
		
		/// Hook up a scrollbar Widget to this for the horizontal axis.
		LUA_WRAP void setHorizontalScrollBar(Widget *bar);
		
		/// Get the vertical scroll bar.
		LUA_WRAP Widget *getVerticalScrollBar(void);
		
		/// Get the horizontal scroll bar.
		LUA_WRAP Widget *getHorizontalScrollBar(void);

		// Constructors/destructors.
		WidgetScrollable(void);
		WidgetScrollable(TiXmlElement *xml);
		virtual ~WidgetScrollable(void);

		// Overloaded from Widget...
		void draw(void);
		bool handleEvent(const WidgetEvent *event);
		float getMinHeight(void);
		float getMinWidth(void);
		void setWidth(float width);
		void setHeight(float height);

	private:
		
		// TODO: Get/set for these.
		
		/// Whether the widget can scroll up/down. Also determines if
		/// the WidgetScrollable itself can be squished smaller than the
		/// contained widget on this axis.
		bool scrollVertically;
		
		/// Whether the widget can scroll left/right. Otherwise the same
		/// as scrollVertically.
		bool scrollHorizontally;
		
		/// Current X scrolling amount. (Draw offset, mouse event
		/// offset)
		float offsetX;
		
		/// Current Y scrolling amount.
		float offsetY;

		std::string verticalScrollbarUID;
		std::string horizontalScrollbarUID;
		
		void updateScrollbars(void);
	
		bool dragScrolling;
		Vector2D dragScrollStart;
		Vector2D dragScrollStartValues;
};

#endif
