/*-----------------------------------------------------------------------

	Wega 1.00 - Demonstrationsprogramm   (c) 1991/92 by D. Rabich
	==================================   Alle Rechte vorbehalten!

	Resourcen

-----------------------------------------------------------------------*/

/* Wegabibliothek */
#include <wega.h>

#include "resource.h"

/* Resourcemakros */
#include "demo.rsh"

extern OBJECT	*demodial,		/* Demo-Objektbaum			*/
				*helpdial,		/* Hilfe-Objektbaum			*/
				*bblks;			/* Objektbaum mit Bitblocks	*/
extern WORD		colors;


/* Objekte initialisieren */
static BOOLEAN rinit(OBJECT *tree, WORD obj, VOID *data)
{
	WORD	v_handle;

	v_handle	= (WORD)data;

	rsrc_obfix(tree, obj);

	{
		OBJECT	*o;

		o	= tree + obj;

		switch(o->ob_type & 0xFF)
		{
			case G_ICON		:
				{
					MFDB	mfdb;

					mfdb.fd_w		= o->ob_spec.iconblk->ib_wicon;
					mfdb.fd_h		= o->ob_spec.iconblk->ib_hicon;
					mfdb.fd_wdwidth = (o->ob_spec.iconblk->ib_wicon + 15)
										/ 16;
					mfdb.fd_nplanes = 1;

					mfdb.fd_addr	= o->ob_spec.iconblk->ib_pmask;
					mfdb.fd_stand	= 1;
					vr_trnfm(v_handle, &mfdb, &mfdb);
					mfdb.fd_addr	= o->ob_spec.iconblk->ib_pdata;
					mfdb.fd_stand	= 1;
					vr_trnfm(v_handle, &mfdb, &mfdb);
				}
				break;

			case G_IMAGE	:
				{
					MFDB	mfdb;

					mfdb.fd_addr	= o->ob_spec.bitblk->bi_pdata;
					mfdb.fd_w		= o->ob_spec.bitblk->bi_wb * 8;
					mfdb.fd_h		= o->ob_spec.bitblk->bi_hl;
					mfdb.fd_wdwidth = (o->ob_spec.bitblk->bi_wb + 1) / 2;
					mfdb.fd_nplanes = 1;
					mfdb.fd_stand	= 1;
					vr_trnfm(v_handle, &mfdb, &mfdb);
				}
				break;
		}
	}

	return(FALSE);
}

/* Resourceinitialisierung */
BOOLEAN rsc_init(VOID)
{
	WORD	v_handle;

	v_handle	= GOpenWorkstation();
	
	if(!v_handle)
		return(FALSE);

	{
		WORD	work_out[57];

		vq_extnd(v_handle, 0, work_out);
		colors	= work_out[13];
	}

	demodial	= rs_trindex[DEMODIAL];
	helpdial	= rs_trindex[HELPDIAL];
	bblks		= rs_trindex[PBITBLKS];

	GTreeWalk(demodial, ROOT, rinit, (VOID*)v_handle);
	GTreeWalk(helpdial, ROOT, rinit, (VOID*)v_handle);
	GTreeWalk(bblks, ROOT, rinit, (VOID*)v_handle);	

	GCloseWorkstation(v_handle);

	return(TRUE);
}

