User Interface for the Sphere Interactor

When the sphere interactor is created, the context sensitive tool bar can show controls that allow the user to set desired interactor specific options, such as whether he wants to create the sphere by defining the center and the radius or by defining the bounding box of the sphere.

Implementing Interactor Gadgets

The sphctrl.c source file implements a gadget that will be shown in the control bar when the sphere interactor is active.

These so called interactor gadgets are derived from 'inc/real/iagad/r3iagad.h' base class and are connected to the primlayer and interactor models using the following attributes:


    R3IAGADA_Interactor
    R3IAGADA_Prims

The base class takes care of setting the model-view relation ship with the gadget and the models so you just need to catch these attributes and get/set their attributes when needed.

Because interactor gadgets are in model-view relationship with interactors, they receive lots of update events (R3IAM_MOVE, for example). The base class takes care of optimzing the update events so that the gadgets don't have to worry about it.

So you should not catch the R3RM_UPDATE method you self. Instead, the system sends you R3IAGADM_NEEDSUPDATE method to query whether your gadget is sensitive to the attribute in question. If so, you should return TRUE.

Later, when appropriate, you will get one R3IAGADM_DOUPDATE method, in which you can update your gadget to reflect the model.

For example, let's assume your gadget has one attribute called SPHIA_DefineMethod. You would then handle the two methods as follows:



    static void *r3iagadm_needsupdate(R3CLASS *cl, R3OBJ *obj, int attrib)
    {
        R3IDATA *self = R3CL_IADDR(cl, obj);

        if( !attrib ||
            attrib == SPHIA_DefineMethod)
            return (void *)TRUE;
        return R3DoSuperA(cl, obj, R3IAGADM_NEEDSUPDATE, (void*)attrib);
    }

    static void *r3iagadm_doupdate(R3CLASS *cl, R3OBJ *obj)
    {
        R3IDATA *self = R3CL_IADDR(cl, obj);
        R3INT p;
        
        R3GetAttrs(self->interactor, SPHIA_DefineMethod, &p, R3TAG_END);
        R3SetAttrs(self->define_method, R3MXGA_Active, v, R3TAG_END);

        return R3DoSuperA(cl, obj, R3IAGADM_DOUPDATE, NULL);
    }

Plugging in new Interactor Gadgets


    #include <real/widget/r3cbar.h>
    
    if(R3ClassFind(R3CLID_CONTROLBAR))
        R3DoClassA2(R3CLID_CONTROLBAR, R3IBCM_INSTALLGADGET, (void *)R3CLID_SDKSPHEREINTERACTOR, (void *)R3CLID_SPHERECONTROLGADGET);