// ---------------------------------------------------------------------------
// 
//   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 WIDGETSLIDER_H
#define WIDGETSLIDER_H

#include "widget.h"

/// Slider Widget. Has a widget that it uses as a child for display
/// purposes (doesn't get events, or only gets minimal events). Slider
/// position is based on a value and max value. Can be horizontal or
/// vertical.
LUA_WRAP class WidgetSlider : public Widget {
	
	public:
	
		// Unique stuff.
		
		/// Get the maximum value.
		LUA_WRAP float getMaxValue(void);
		
		/// Set the maximum value.
		LUA_WRAP void setMaxValue(float maxValue);
		
		/// Get the current value.
		LUA_WRAP float getValue(void);
		
		/// Set the current value.
		LUA_WRAP void setValue(float value);
		
		/// Set if this is vertical (true) or horizontal (false).
		LUA_WRAP void setVertical(bool vertical);
		
		/// Get vertical flag.
		LUA_WRAP bool getVertical(void);
		
		/// Set inverted (goes bottom-to-top or right-to-left).
		LUA_WRAP void setInverted(bool inverted);
		
		/// Get inverted.
		LUA_WRAP bool getInverted(void);
		
		/// Set small step size (think arrow keys / mouse wheel).
		LUA_WRAP void setSmallStep(float step);

		/// Get small step size.
		LUA_WRAP float getSmallStep(void);
		
		/// Set large step size (think pgup/pgdown).
		LUA_WRAP void setBigStep(float step);
		
		/// Get large step size.
		LUA_WRAP float getBigStep(void);
		
		/// Set the image for the thingy (ninepatch preferable).
		LUA_WRAP void setThingyImage(const std::string &image);
		
		/// Set the size of the thingy on the axis that it moves on.
		/// The other axis is always stretched to the size of the
		/// scrollbar.
		LUA_WRAP void setThingySize(float thingySize);
		
		void overrideDragStart(float mousex, float mousey);
		void overrideDragEnd();
		
		// Constructor/destructor.
		WidgetSlider(void);
		// TODO: XML.
		virtual ~WidgetSlider(void);
		
		// Inherited stuff.
		void draw(void);
		bool handleEvent(const WidgetEvent *event);
		float getMinWidth(void);
		float getMinHeight(void);
		void setWidth(float newWidth);
		void setHeight(float newHeight);
		bool isSizeDirty(void);
	
	private:
		
		bool intValuesOnly;
		
		float value;
		float maxValue;
		
		// Orientation. vertical or !vertical for horizontal.
		bool vertical;
		
		// Adjusts slider position and size. Clamps value to
		// 0..maxValue. Call after everything.
		void fixup(void);
		
		// Get the offset to draw the thingy from based on the thingy's
		// size, this Widget's size, and the value/maxValue.
		float getThingyDrawOffset(void);
		
		// The thing that gets dragged around. Yes, official name is
		// now "thingy". Deal with it.
		Widget *thingy;
	
		// These handle mouse coordinates during a drag so we know
		// exactly where to set the value even after multiple frames
		// of dragging.
		float mouseDragStartX;
		float mouseDragStartY;
		float mouseDragStartValue;
		bool draggingThingy;
	
		float smallStep;
		float bigStep;
		bool inverted;
		float thingySize;
};

#endif
