// Copyright 1999
// College of Computer Science
// Northeastern University Boston MA 02115

// This software may be used for educational purposes as long as this copyright
// notice is retained at the top of all files

// Should this software be modified, the words "Modified from Original" must be
// included as a comment below this notice

// All publication rights are retained.  This software or its documentation may
// not be published in any media either in whole or in part.

///////////////////////////////////////////////////////////////////////////////

// GraphicsObject.cpp

///////////////////////////////////////////////////////////////////////////////

#include "CoreTools.h"
#include "SystemBase.h"
#include "GraphicsObject.h"


void GraphicsObject::Draw(GraphicsWindow& G) const {
	// return if G is not open

	if(! G.IsOpen() )
		return;

	// Step 1. Prepare graphics resources

	G.PrepareGraphics();

	// Step 2. Clone the object

	GraphicsObject* clone = Clone();

	// Step 3. Call clone->DrawDetails() to do the graphics

	clone->DrawDetails(G);

	// Step 4: If permanent then insert the clone into the DrawList
	// otherwise throw away clone

	if (IsPermanent())
		G.DrawListInsert(clone);
	else
		delete clone;

	// Step 5. Release graphics resources

	G.ReleaseGraphics();
}


void GraphicsObject::Draw(int index) const {

	GraphicsWindow* gwp = GraphicsWindowPtr(index);

	if (gwp)
		Draw(*gwp);
}


void IndirectObject::Draw(int index) const {

	GraphicsWindow* gwp = GraphicsWindowPtr(index);

	if (gwp)
		Draw(*gwp);
}

