#include "widget.h"

Widget::Widget()
{
	// Set default state
	_visible = true;
	_enabled = true;
	_touchable = true;
	_dragging = false;
	
	// No parent now
	_parent = NULL;
}

Widget::~Widget()
{
	// Empty destructor
}

void Widget::setDimensions(Rect r)
{
	// Set up box for widget
	move(r.x, r.y);
	resize(r.width, r.height);
}

Rect Widget::getDimensions()
{
	// Return screen location
	Rect tRect = _rect;
	
	// Add on parent position if needed
	if(_parent)
	{
		Rect pRect = _parent->getDimensions();
		
		tRect.x += pRect.x;
		tRect.y += pRect.y;
	}
	
	return tRect;
}

Rect Widget::getAbsoluteDimensions()
{
	// Return screen location without parent
	return _rect;
}

void Widget::move(int x, int y)
{
	// Move widget
	_rect.x = x;
	_rect.y = y;
}

void Widget::resize(int width, int height)
{
	// Ensure width/height is a multiple of 4
	while(width % 4) { width++; };
	while(height % 4) { height++; };
	
	// Resize widget
	_rect.width = width;
	_rect.height = height;
}

void Widget::draw()
{
	// Nothing to do
}

void Widget::cursorDown(int x, int y, Action a)
{
	// Ignoring input
}

void Widget::cursorMove(int x, int y)
{
	// Ignoring input
}

void Widget::cursorUp(int x, int y, Action a)
{
	// Ignoring input
}

void Widget::cursorOut()
{
	// Ignoring input
}

void Widget::setTouchable(bool touchable)
{
	// Toggle visible state
	_touchable = touchable;
}

bool Widget::getTouchable()
{
	// Make parameter visible to other classes
	return _touchable;
}

void Widget::setVisible(bool visible)
{
	// Toggle visible state
	_visible = visible;
}

bool Widget::getVisible()
{
	// Make parameter visible to other classes
	return _visible;
}

void Widget::setEnabled(bool enabled)
{
	// Toggle enabled state
	_enabled = enabled;
}

bool Widget::getEnabled()
{
	// Make parameter visible to other classes
	return _enabled;
}

bool Widget::isDragging()
{
	// Return drag status
	return _dragging;
}

void Widget::setParent(Widget *parent)
{
	// Remember parent widget
	_parent = parent;
}

