/**************************************************************************
 * OBJSTCHG.C - Change object state, with optional redraw.
 *************************************************************************/

#include "gemfintl.h"

#ifdef GEMFAST_PROTOS
  void obj_stchange(OBJECT *ptree, short object, short newstate,
					int   drawflag, ...)
#else
  void obj_stchange(ptree, object, newstate, drawflag)
	register OBJECT *ptree;
	short			  object;
	short			  newstate;
	int 			  drawflag;
#endif
{
	GRECT			*optional_clip;
	GRECT			*pclip;
	va_list 		args;

	va_start(args, drawflag);
	optional_clip = va_arg(args, GRECT *);
	va_end(args);

/*
 * check the newstate value. if the high bit is set, AND the newstate
 * with the current state, else OR them.
 */

	if (newstate & 0x8000) {
		newstate &= ptree[object].ob_state;
	}
	else {
		newstate |= ptree[object].ob_state;
	}

/*
 * if the drawflag is set, redraw the object.
 * if the drawflag says a clipping rectangle was passed, use it,
 * else use root object as the clipping rectangle for the redraw.
 */

	if (drawflag == OBJ_CLIPDRAW) {
		drawflag = OBJ_WITHDRAW;	/* xlate from 2 to 1							 */
		pclip = optional_clip;
	} else {
		pclip = (GRECT *)&ptree->ob_x;
	}

	objc_change(ptree, object, 0, RECTVALS(pclip), newstate, drawflag);

}



