//================================== // VRMenuMgrLocal::CreateObject // creates a new menu object menuHandle_t VRMenuMgrLocal::CreateObject( VRMenuObjectParms const & parms ) { if ( !Initialized ) { LOG( "VRMenuMgrLocal::CreateObject - manager has not been initialized!" ); return menuHandle_t(); } // validate parameters if ( parms.Type >= VRMENU_MAX ) { LOG( "VRMenuMgrLocal::CreateObject - Invalid menu object type: %i", parms.Type ); return menuHandle_t(); } // create the handle first so we can enforce setting it be requiring it to be passed to the constructor int index = -1; if ( FreeList.GetSizeI() > 0 ) { index = FreeList.Back(); FreeList.PopBack(); } else { index = ObjectList.GetSizeI(); } UInt32 id = ++CurrentId; menuHandle_t handle = ComposeHandle( index, id ); //LOG( "VRMenuMgrLocal::CreateObject - handle is %llu", handle.Get() ); VRMenuObject * obj = new VRMenuObjectLocal( parms, handle ); if ( obj == NULL ) { LOG( "VRMenuMgrLocal::CreateObject - failed to allocate menu object!" ); OVR_ASSERT( obj != NULL ); // this would be bad -- but we're likely just going to explode elsewhere return menuHandle_t(); } obj->Init( parms ); if ( index == ObjectList.GetSizeI() ) { // we have to grow the array ObjectList.PushBack( obj ); } else { // insert in existing slot OVR_ASSERT( ObjectList[index] == NULL ); ObjectList[index ] = obj; } return handle; }
//============================== // VRMenuEventHandler::HandleEvents void VRMenuEventHandler::HandleEvents( OvrGuiSys & guiSys, VrFrame const & vrFrame, menuHandle_t const rootHandle, Array< VRMenuEvent > const & events ) const { VRMenuObject * root = guiSys.GetVRMenuMgr().ToObject( rootHandle ); if ( root == NULL ) { return; } // find the list of all objects that are in the focused path Array< menuHandle_t > focusPath; FindTargetPath( guiSys, rootHandle, FocusedHandle, focusPath ); Array< menuHandle_t > targetPath; for ( int i = 0; i < events.GetSizeI(); ++i ) { VRMenuEvent const & event = events[i]; switch ( event.DispatchType ) { case EVENT_DISPATCH_BROADCAST: { // broadcast to everything BroadcastEvent( guiSys, vrFrame, event, root ); } break; case EVENT_DISPATCH_FOCUS: // send to the focus path only -- this list should be parent -> child order DispatchToPath( guiSys, vrFrame, event, focusPath, false ); break; case EVENT_DISPATCH_TARGET: if ( targetPath.GetSizeI() == 0 || event.TargetHandle != targetPath.Back() ) { targetPath.Clear(); FindTargetPath( guiSys, rootHandle, event.TargetHandle, targetPath ); } DispatchToPath( guiSys, vrFrame, event, targetPath, false ); break; default: OVR_ASSERT( !"unknown dispatch type" ); break; } } }