How to Create a vgPicker Call-back Function

 

Vega Code Example

 

 

 

 

 

 
 

This example illustrates how to use a call-back function with a vgPicker:

  • Create an instance of call-back function for vgPicker

  • How to add call-back function to the vgPicker

  • How to use the vgCommon function vgGetProp

  • How to get a pointer to the picked item from the call-back

  • How to use vgPrint to show information about a vgClass

 

The vgPicker supports the following call-back events

  • VGPICK_PICKED

  • VGPICK_UNPICKED

  • VGPICK_PICKED_POSCHANGE

  • VGPICK_NEW_MOVE        

  • VGPICK_NEW_MULTIMOVE

 

 

 
   
 

 

 
 
 
 

            

#include <stdlib.h>       //  definition of print                

#include "vg.h"           //  main include file for Vega         

#include "pf.h"           //  main include file for Performer    

 
//  
//  
//  add a call back on the pick event, Note we do not 
//  pass in any user data as the vgPicker passes the 
//  picked item through udata pointer 
//  
//  
vgAddFunc( vgFindPicker("my_picker"), VGPICK_PICKED, newPickEventCB, NULL );
  
 
 
void 
newPickEventCB( vgCommon* handle, void *udata ) {
// #################################################################
// #
// # Static member function  
// #
// #    This Call-back function when the vpPicker picks a new item
// #
// #################################################################
vgPicker  *picker     = NULL;
vgCommon  *pickedItem = NULL;
  
    // 
    //  The *handle is always a pointer to the      
    //  vgClass instance we placed on the call-back 
    // 
    picker = (vgPicker*)handle;
 
    // 
    // 
    //  Normally on Vega Calls instance call backs the user supplies 
    //  udata which should be structure created from the shared arena 
    //  
    // 
    //  However with the picked event the vgPicker uses the udata to 
    //  pass in a pointer to the item tha has been picked item which
    //  has to be cast to its correct type 
    // 
    //  
 
    int which = vgGetProp( picker, VGPICK_HL_LEVEL );
 
    switch( which ){
 
 
        case VGPICK_OBJECT   :   
        case VGPICK_PART     :   
        case VGPICK_PART_DCS :
        case VGPICK_PLAYER   :
 
                pickedItem = dynamic_cast<vgCommon  *>(udata);
 
                // 
                // Sanity check do we have a vega class pointer
                // 
                if( pickedItem == NULL )
                    return;
 
                
                //  
                // Do something with the picked item 
                // 
                vgPrint( pickedItem );
 
                break;
 
 
        case VGPICK_GEODE :
                
                printf("pfGeode Picked  0x%p\n", udata );
 
                break;
 
            
        case VGPICK_GEOSET :
                printf("pfGeoSet Picked  0x%p\n", udata );
 
                break;
             
        default:
 
                printf("Unknown Picker Level\n");
 
                break;
        }
 
    
} //  newPickEventCB
 
 
 
 
 
 
 
 
 

 

 

© Copyright 2004 Gordon Tomlinson  All Rights Reserved.

All logos, trademarks and copyrights in this site are property of their respective owner.