
/**************************************************************************
 *
 * AESFAST PD utilties.
 *
 *  Object-related utilities 1...
 *    obj_flchange
 *    obj_stchange
 *************************************************************************/

#include <gemfast.h>

/*-------------------------------------------------------------------------
 * obj_flchange - Change ob_flags, with optional redraw.
 *-----------------------------------------------------------------------*/

void
obj_flchange(ptree, object, newflags, drawflag)
    register OBJECT *ptree;
    int             object;
    int             newflags;
    int             drawflag;
{
    GRECT           clip_rect;
    
/*
 * check the newflags value. if the high bit is set, AND the newflags
 * with the current flags, else OR them.
 */
 
    if (newflags & 0x8000) {
        ptree[object].ob_flags &= newflags;
    }
    else {
        ptree[object].ob_flags |= newflags;
    }

/* 
 * if drawflag is true, we need to do a redraw starting at the changed
 * object's tree root (this is in case the HIDETREE flag is being changed),
 * but the redraw must be clipped by the object we're trying to update.
 * we get the screen x/y/w/h of the object, and expand it by 3 pixels to
 * allow for shadowed, outlined, etc, and use it as a clipping rectangle
 * for the objc_draw.
 */

    if (drawflag) {
        obj_offxywh(ptree, object, &clip_rect);
        rc_gadjust(&clip_rect, 3, 3); 
        objc_draw(ptree, R_TREE, MAX_DEPTH, clip_rect);
    }
}

/*-------------------------------------------------------------------------
 * obj_stchange - Change ob_state, with optional redraw.
 *-----------------------------------------------------------------------*/

void
obj_stchange(ptree, object, newstate, drawflag)
    register OBJECT *ptree;
    int             object;
    int             newstate;
    int             drawflag;
{
    GRECT           clip_rect;
    
/*
 * check the newstate value. if the high bit is set, AND the newstate
 * with the current state, else OR them.
 */
 
    if (newstate & 0x8000) {
        ptree[object].ob_state &= newstate;
    }
    else {
        ptree[object].ob_state |= newstate;
    }

/*
 * if the drawflag is set, redraw the object.  Use the x/y/w/h of the
 * root object as the clipping rectangle for the redraw.
 */

    if (drawflag) {
        obj_offxywh(ptree, R_TREE, &clip_rect);
        objc_draw(ptree, object, MAX_DEPTH, clip_rect);
    }
}

