/*	File: Figure.cpp
 *
 *	Design and Implementation Description:
 *		The commands Show, Hide use polymorphic calls of Draw.
 *	History:
 *		Date:		 Author:	 Change:
 *		97-05-05	 KHU		 Creation.
 */

#include "Figure.h"

#include <iostream.h>

#include <assert.h>
#include <graphics.h>

	void Figure::Show ()
	{
		Draw ();
		state = shown;
		CheckInvariant ();
		assert(state == shown);
	}; // Show

	void Figure::Hide ()
	{
		int color = getcolor ();
		setcolor (getbkcolor ());
		Draw ();
		setcolor (color);
		state = hidden;
		CheckInvariant ();
		assert(state == hidden);
	}; // Hide

	void Figure::Move (const CoordinatePair & delta)
	{
		cout << "Figure.Move: from ";
		FigureState s = state;
		if (s == shown)
		{
			Hide ();
		};
		cout << refPoint.x << " "
			  << refPoint.y << " to ";
		refPoint.x += delta.x;
		refPoint.y += delta.y;
		cout << refPoint.x << " "
			  << refPoint.y << " " << endl;
		if (s == shown)
		{
			Show ();
		};
//		CheckInvariant ();
		assert(s == state);
	}; // Move

	void Figure::MoveTo (const CoordinatePair & newRefPoint)
	{
		FigureState s = state;
		if (s == shown)
		{
			Hide ();
		};
		refPoint = newRefPoint;
		if (s == shown)
		{
			Show ();
		};
		CheckInvariant ();
		assert(s == state);
	}; // MoveTo

	void Figure::CheckInvariant ()
	{
		assert(coordinateMin <= refPoint.x);
		assert(refPoint.x <= coordinateMax);
		assert(coordinateMin <= refPoint.y);
		assert(refPoint.y <= coordinateMax);
	}; // CheckInvariant

// End of Figure.

