/*	XGPicture.cpp
 *
 *		Picture drawing routines
 */

/*  YAAF - Yet another application framework
 *  Copyright (C) 1997, 1998 William Edward Woody
 *  
 *  This library is free software; you can redistribute it
 *  and/or modify it under the terms of the GNU Library
 *  General Public License as published by the Free Software
 *  Foundation; either version 2 of the License, or any
 *  later version.
 *  
 *  This library is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE. See the GNU Library General Public License for
 *  more details.
 *  
 *  You should have received a copy of the GNU Library General
 *  Public License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#include <XConfig.h>			// must be first to optimize compile on MSVC++
#include <XDraw.h>
#include <XImageControls.h>

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

/*	@F"XGPicture::XGPicture" @I
 *
 *		Construction
 */

XGPicture::XGPicture(XGOwner *parent, XGArgStream &init) : XGView(parent,init)
{
	fPicture = init.ReadInteger();
	fWidth = init.ReadInteger();
	fHeight = init.ReadInteger();
}

XGPicture::XGPicture(XGOwner *parent, XGSImageInitRecord &init) : XGView(parent,init.v)
{
	fPicture = init.image;
	fWidth = init.width;
	fHeight = init.height;
}

/*	@F"XGPicture::~XGPicture" @I
 *
 *		Destruction
 */

XGPicture::~XGPicture()
{
}

/************************************************************************/
/*																		*/
/*	Events																*/
/*																		*/
/************************************************************************/

/*	@F"XGPicture::DoDrawView" @I
 *
 *		Draw the curent view
 */

void XGPicture::DoDrawView(Rect u)
{
	XGDraw draw(this);
	Rect r;
	
	draw.Draw3DRect(u,KXGEBackground);
	
	r = GetContentRect();
	if (fWidth > 0) {
		r.left = (r.left + r.right - fWidth) / 2;
		r.right = r.left + fWidth;
	}
	if (fHeight > 0) {
		r.top = (r.top + r.bottom - fHeight) / 2;
		r.bottom = r.top + fHeight;
	}
	
	::InsetRect(&r,-1,-1);
	draw.Draw3DRect(r,KXGEInset);
	::InsetRect(&r,1,1);
	
	draw.DrawPicture(fPicture,r.left,r.top);
}
