void UILabel::SetText( const char *text ) { VRMenuObject * object = GetMenuObject(); assert( object ); object->SetText( text ); CalculateTextOffset(); }
void UILabel::SetText( const String &text ) { VRMenuObject * object = GetMenuObject(); assert( object ); object->SetText( text.ToCStr() ); CalculateTextOffset(); }
//================================== // VRMenuMgrLocal::ToObject // Return the object for a menu handle. VRMenuObject * VRMenuMgrLocal::ToObject( menuHandle_t const handle ) const { int index; UInt32 id; DecomposeHandle( handle, index, id ); if ( id == INVALID_MENU_OBJECT_ID ) { return NULL; } if ( !HandleComponentsAreValid( index, id ) ) { LOG( "VRMenuMgrLocal::ToObject - invalid handle." ); return NULL; } if ( index >= ObjectList.GetSizeI() ) { LOG( "VRMenuMgrLocal::ToObject - index out of range." ); return NULL; } VRMenuObject * object = ObjectList[index]; if ( object == NULL ) { LOG( "VRMenuMgrLocal::ToObject - slot empty." ); return NULL; // this can happen if someone is holding onto the handle of an object that's been freed } if ( object->GetHandle() != handle ) { // if the handle of the object in the slot does not match, then the object the handle refers to was deleted // and a new object is in the slot LOG( "VRMenuMgrLocal::ToObject - slot mismatch." ); return NULL; } return object; }
//============================== // VRMenuEventHandler::DispatchToPath bool VRMenuEventHandler::DispatchToPath( OvrGuiSys & guiSys, VrFrame const & vrFrame, VRMenuEvent const & event, Array< menuHandle_t > const & path, bool const log ) const { // send to the focus path only -- this list should be parent -> child order for ( int i = 0; i < path.GetSizeI(); ++i ) { VRMenuObject * obj = guiSys.GetVRMenuMgr().ToObject( path[i] ); char const * const indent = " "; // set to if ( obj != NULL && DispatchToComponents( guiSys, vrFrame, event, obj ) ) { if ( log ) { LOG( "%sDispatchToPath: %s, object '%s' consumed event.", &indent[64 - i * 2], VRMenuEvent::EventTypeNames[event.EventType], ( obj != NULL ? obj->GetText().ToCStr() : "<null>" ) ); } return true; // consumed by a component } if ( log ) { LOG( "%sDispatchToPath: %s, object '%s' passed event.", &indent[64 - i * 2], VRMenuEvent::EventTypeNames[event.EventType], obj != NULL ? obj->GetText().ToCStr() : "<null>" ); } } return false; }
void UILabel::SetTextOffset( Vector3f const & pos ) { VRMenuObject * object = GetMenuObject(); assert( object ); TextOffset = pos; object->SetTextLocalPosition( TextOffset + JustificationOffset ); }
//============================== // OvrSliderComponent::SetCaretPoseFromFrac void OvrSliderComponent::SetCaretPoseFromFrac( OvrVRMenuMgr & menuMgr, VRMenuObject * self, float const frac ) { OVR_UNUSED( frac ); VRMenuObject * caret = menuMgr.ToObject( self->ChildHandleForId( menuMgr, ScrubberId ) ); if ( caret != NULL ) { Posef curPose = CaretBasePose; float range = MaxValue - MinValue; float frac = floor( SliderFrac * range ) / range; curPose.Position += ( LocalSlideDelta * -0.5f ) + LocalSlideDelta * frac; caret->SetLocalPose( curPose ); } // find the fill object and scale it menuHandle_t fillHandle = Menu.HandleForId( menuMgr, FillId ); VRMenuObject * fillObj = menuMgr.ToObject( fillHandle ); if ( fillObj != NULL ) { Vector4f clipUVs( 0.0f, 1.0f - SliderFrac, 1.0f, 1.0f ); VRMenuSurface & surf = fillObj->GetSurface( 0 ); surf.SetClipUVs( clipUVs ); //LOG( "SliderFrac = %.2f", SliderFrac ); //LOG( "Setting clip UVs to ( %.2f, %.2f, %.2f, %.2f )", clipUVs.x, clipUVs.y, clipUVs.z, clipUVs.w ); } }
//============================== // OvrSliderComponent::OnFrameUpdate eMsgStatus OvrSliderComponent::OnFrameUpdate( App * app, VrFrame const & vrFrame, OvrVRMenuMgr & menuMgr, VRMenuObject * self, VRMenuEvent const & event ) { if ( TouchDown ) { UpdateText( menuMgr, self, BubbleId ); UpdateText( menuMgr, self, TextId ); } if ( BubbleFadeOutTime > 0.0 ) { if ( ovr_GetTimeInSeconds() >= BubbleFadeOutTime ) { BubbleFadeOutTime = -1.0; BubbleFader.StartFadeOut(); } } VRMenuObject * bubble = menuMgr.ToObject( self->ChildHandleForId( menuMgr, BubbleId ) ); if ( bubble != NULL ) { float const fadeTime = 0.5f; float const fadeRate = 1.0 / fadeTime; BubbleFader.Update( fadeRate, vrFrame.DeltaSeconds ); Vector4f color = bubble->GetColor(); color.w = BubbleFader.GetFinalAlpha(); bubble->SetColor( color ); Vector4f textColor = bubble->GetTextColor(); textColor.w = color.w; bubble->SetTextColor( textColor ); } return MSG_STATUS_ALIVE; }
void UILabel::SetFontScale( float const scale ) { VRMenuObject * object = GetMenuObject(); assert( object ); FontParms.Scale = scale; object->SetFontParms( FontParms ); }
void UILabel::SetFontParms( const VRMenuFontParms &parms ) { FontParms = parms; VRMenuObject * object = GetMenuObject(); if ( object != NULL ) { object->SetFontParms( parms ); } }
void OvrScrollBarComponent::SetBaseColor( OvrVRMenuMgr & menuMgr, VRMenuObject * self, const Vector4f & color ) { // Set alpha on the base - move this to somewhere more explicit if needed VRMenuObject * base = menuMgr.ToObject( self->ChildHandleForId( menuMgr, ScrollBarBaseId ) ); if ( base != NULL ) { base->SetSurfaceColor( 0, color ); } }
void ResumeMovieView::SetPosition( OvrVRMenuMgr & menuMgr, const Vector3f &pos ) { menuHandle_t centerRootHandle = Menu->HandleForId( menuMgr, ID_CENTER_ROOT ); VRMenuObject * centerRoot = menuMgr.ToObject( centerRootHandle ); OVR_ASSERT( centerRoot != NULL ); Posef pose = centerRoot->GetLocalPose(); pose.Position = pos; centerRoot->SetLocalPose( pose ); }
//============================== // FindTargetPath static void FindTargetPath( OvrGuiSys & guiSys, menuHandle_t const curHandle, Array< menuHandle_t > & targetPath ) { VRMenuObject * obj = guiSys.GetVRMenuMgr().ToObject( curHandle ); if ( obj != NULL ) { FindTargetPath( guiSys, obj->GetParentHandle(), targetPath ); targetPath.PushBack( curHandle ); } }
void UILabel::SetVerticalAlign( const VerticalJustification vert ) { FontParms.AlignVert = vert; VRMenuObject * object = GetMenuObject(); if ( object != NULL ) { object->SetFontParms( FontParms ); CalculateTextOffset(); } }
void UILabel::SetHorizontalAlign( const HorizontalJustification horiz ) { FontParms.AlignHoriz = horiz; VRMenuObject * object = GetMenuObject(); if ( object != NULL ) { object->SetFontParms( FontParms ); CalculateTextOffset(); } }
//============================== // FindTargetPath static void FindTargetPath( OvrVRMenuMgr const & menuMgr, menuHandle_t const curHandle, Array< menuHandle_t > & targetPath ) { VRMenuObject * obj = menuMgr.ToObject( curHandle ); if ( obj != NULL ) { FindTargetPath( menuMgr, obj->GetParentHandle(), targetPath ); targetPath.PushBack( curHandle ); } }
//================================== // 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; }
//============================== // OvrSliderComponent::SetCaretPoseFromFrac void OvrSliderComponent::SetCaretPoseFromFrac( OvrVRMenuMgr & menuMgr, VRMenuObject * self, float const frac ) { VRMenuObject * caret = menuMgr.ToObject( self->ChildHandleForId( menuMgr, ScrubberId ) ); if ( caret != NULL ) { Posef curPose = CaretBasePose; float range = MaxValue - MinValue; float frac = floor( SliderFrac * range ) / range; curPose.Position += ( LocalSlideDelta * -0.5f ) + LocalSlideDelta * frac; caret->SetLocalPose( curPose ); } }
//============================== // OvrSliderComponent::OnInit eMsgStatus OvrSliderComponent::OnInit( App * app, VrFrame const & vrFrame, OvrVRMenuMgr & menuMgr, VRMenuObject * self, VRMenuEvent const & event ) { // find the starting offset of the caret LOG( "OvrSliderComponent - VRMENU_EVENT_INIT" ); VRMenuObject * caret = menuMgr.ToObject( self->ChildHandleForId( menuMgr, ScrubberId ) ); if ( caret != NULL ) { CaretBasePose = caret->GetLocalPose(); } SetCaretPoseFromFrac( menuMgr, self, SliderFrac ); UpdateText( menuMgr, self, BubbleId ); return MSG_STATUS_ALIVE; }
//============================== // OvrSliderComponent::UpdateText void OvrSliderComponent::UpdateText( OvrVRMenuMgr & menuMgr, VRMenuObject * self, VRMenuId_t const id ) { if ( !id.IsValid() ) { return; } VRMenuObject * obj = menuMgr.ToObject( self->ChildHandleForId( menuMgr, id ) ); if ( obj != NULL ) { char valueStr[127]; GetStringValue( valueStr, sizeof( valueStr ) ); obj->SetText( valueStr ); } }
//============================== // OvrSliderComponent::OnInit eMsgStatus OvrSliderComponent::OnInit( OvrGuiSys & guiSys, VrFrame const & vrFrame, VRMenuObject * self, VRMenuEvent const & event ) { OVR_UNUSED( vrFrame ); OVR_UNUSED( event ); // find the starting offset of the caret //LOG( "OvrSliderComponent - VRMENU_EVENT_INIT" ); VRMenuObject * caret = guiSys.GetVRMenuMgr().ToObject( self->ChildHandleForId( guiSys.GetVRMenuMgr(), ScrubberId ) ); if ( caret != NULL ) { CaretBasePose = caret->GetLocalPose(); } SetCaretPoseFromFrac( guiSys.GetVRMenuMgr(), self, SliderFrac ); UpdateText( guiSys.GetVRMenuMgr(), self, BubbleId ); return MSG_STATUS_ALIVE; }
void UIDiscreteSlider::AddCells( unsigned int maxValue, unsigned int startValue, float cellSpacing ) { MaxValue = maxValue; StartValue = startValue; DiscreteSliderComponent = new UIDiscreteSliderComponent( *this, StartValue ); OVR_ASSERT( DiscreteSliderComponent ); AddComponent( DiscreteSliderComponent ); float cellOffset = 0.0f; const float pixelCellSpacing = cellSpacing * VRMenuObject::DEFAULT_TEXEL_SCALE; VRMenuFontParms fontParms( HORIZONTAL_CENTER, VERTICAL_CENTER, false, false, false, 1.0f ); Vector3f defaultScale( 1.0f ); for ( unsigned int cellIndex = 0; cellIndex <= MaxValue; ++cellIndex ) { const Posef pose( Quatf( Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ), Vector3f( cellOffset, 0.f, 0.0f ) ); cellOffset += pixelCellSpacing; VRMenuObjectParms cellParms( VRMENU_BUTTON, Array< VRMenuComponent* >(), VRMenuSurfaceParms(), "", pose, defaultScale, fontParms, Menu->AllocId(), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); UICell * cellObject = new UICell( GuiSys ); cellObject->AddToDiscreteSlider( Menu, this, cellParms ); cellObject->SetImage( 0, SURFACE_TEXTURE_DIFFUSE, CellOffTexture ); UICellComponent * cellComp = new UICellComponent( *DiscreteSliderComponent, cellIndex ); VRMenuObject * object = cellObject->GetMenuObject(); OVR_ASSERT( object ); object->AddComponent( cellComp ); DiscreteSliderComponent->AddCell( cellObject ); } DiscreteSliderComponent->HighlightCells( StartValue ); }
void OvrPanoMenu::UpdateButtonsState( const OvrMetaDatum * const ActivePano, bool showSwipeOverride /*= false*/ ) { // Reset button time ButtonCoolDown = BUTTON_COOL_DOWN_SECONDS; // Update favo bool isFavorite = false; for ( int i = 0; i < ActivePano->Tags.GetSizeI( ); ++i ) { if ( ActivePano->Tags[ i ] == "Favorites" ) { isFavorite = true; break; } } VRMenuObject * favoritesButtonObject = MenuMgr.ToObject( FavoritesButtonHandle ); OVR_ASSERT( favoritesButtonObject != NULL ); if ( OvrSurfaceToggleComponent * favToggleComp = favoritesButtonObject->GetComponentByName<OvrSurfaceToggleComponent>() ) { const int fav = isFavorite ? 2 : 0; favToggleComp->SetGroupIndex( fav ); } VRMenuObject * swipeRight = MenuMgr.ToObject( SwipeRightIndicatorHandle ); OVR_ASSERT( swipeRight != NULL ); VRMenuObject * swipeLeft = MenuMgr.ToObject( SwipeLeftIndicatorHandle ); OVR_ASSERT( swipeLeft != NULL ); const bool showSwipeIndicators = showSwipeOverride || ( Photos->GetNumPanosInActiveCategory( ) > 1 ); VRMenuObjectFlags_t flagsLeft = swipeRight->GetFlags( ); VRMenuObjectFlags_t flagsRight = swipeRight->GetFlags( ); if ( showSwipeIndicators ) { flagsLeft &= ~VRMenuObjectFlags_t( VRMENUOBJECT_DONT_RENDER ); flagsRight &= ~VRMenuObjectFlags_t( VRMENUOBJECT_DONT_RENDER ); } else { flagsLeft |= VRMenuObjectFlags_t( VRMENUOBJECT_DONT_RENDER ); flagsRight |= VRMenuObjectFlags_t( VRMENUOBJECT_DONT_RENDER ); } swipeLeft->SetFlags( flagsLeft ); swipeRight->SetFlags( flagsRight ); }
void OvrScrollBarComponent::UpdateScrollBar( OvrVRMenuMgr & menuMgr, VRMenuObject * self, const int numElements ) { NumOfItems = numElements; if ( IsVertical ) { ScrollBarCurrentbaseLength = ScrollBarBaseHeight; } else { ScrollBarCurrentbaseLength = ScrollBarBaseWidth; } ScrollBarCurrentThumbLength = ScrollBarCurrentbaseLength / NumOfItems; ScrollBarCurrentThumbLength = ( ScrollBarCurrentThumbLength < BASE_THUMB_WIDTH ) ? BASE_THUMB_WIDTH : ScrollBarCurrentThumbLength; if ( IsVertical ) { ScrollBarThumbHeight = ScrollBarCurrentThumbLength; } else { ScrollBarThumbWidth = ScrollBarCurrentThumbLength; } VRMenuObject * thumb = menuMgr.ToObject( self->ChildHandleForId( menuMgr, ScrollBarThumbId ) ); if ( thumb != NULL && NumOfItems > 0 ) { thumb->SetSurfaceDims( 0, Vector2f( ScrollBarThumbWidth, ScrollBarThumbHeight ) ); thumb->RegenerateSurfaceGeometry( 0, false ); } VRMenuObject * base = menuMgr.ToObject( self->ChildHandleForId( menuMgr, ScrollBarBaseId ) ); if ( thumb != NULL ) { base->SetSurfaceDims( 0, Vector2f( ScrollBarBaseWidth, ScrollBarBaseHeight ) ); base->RegenerateSurfaceGeometry( 0, false ); } }
//================================== // VRMenuMgrLocal::FreeObject // Frees a menu object. If the object is a child of a parent object, this will // also remove the child from the parent. void VRMenuMgrLocal::FreeObject( menuHandle_t const handle ) { int index; UInt32 id; DecomposeHandle( handle, index, id ); if ( !HandleComponentsAreValid( index, id ) ) { return; } if ( ObjectList[index] == NULL ) { // already freed return; } VRMenuObject * obj = ObjectList[index]; // remove this object from its parent's child list if ( obj->GetParentHandle().IsValid() ) { VRMenuObject * parentObj = ToObject( obj->GetParentHandle() ); if ( parentObj != NULL ) { parentObj->RemoveChild( *this, handle ); } } // free all of this object's children obj->FreeChildren( *this ); delete obj; // empty the slot ObjectList[index] = NULL; // add the index to the free list FreeList.PushBack( index ); CondenseList(); }
OvrVideoMenu::OvrVideoMenu( OvrGuiSys & guiSys, OvrMetaData & metaData, float radius ) : VRMenu( MENU_NAME ) , MetaData( metaData ) , LoadingIconHandle( 0 ) , AttributionHandle( 0 ) , BrowserButtonHandle( 0 ) , VideoControlButtonHandle( 0 ) , Radius( radius ) , ButtonCoolDown( 0.0f ) , OpenTime( 0.0 ) { // Init with empty root Init( guiSys, 0.0f, VRMenuFlags_t() ); // Create Attribution info view Array< VRMenuObjectParms const * > parms; Array< VRMenuComponent* > comps; VRMenuId_t attributionPanelId( ID_CENTER_ROOT.Get() + 10 ); comps.PushBack( new OvrVideoMenuRootComponent( *this ) ); Quatf rot( DOWN, 0.0f ); Vector3f dir( -FWD ); Posef panelPose( rot, dir * Radius ); Vector3f panelScale( 1.0f ); const VRMenuFontParms fontParms( true, true, false, false, true, 0.525f, 0.45f, 1.0f ); VRMenuObjectParms attrParms( VRMENU_STATIC, comps, VRMenuSurfaceParms(), "Attribution Panel", panelPose, panelScale, Posef(), Vector3f( 1.0f ), fontParms, attributionPanelId, VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &attrParms ); AddItems( guiSys, parms, GetRootHandle(), false ); parms.Clear(); comps.Clear(); AttributionHandle = HandleForId( guiSys.GetVRMenuMgr(), attributionPanelId ); VRMenuObject * attributionObject = guiSys.GetVRMenuMgr().ToObject( AttributionHandle ); OVR_ASSERT( attributionObject != NULL ); //Browser button float const ICON_HEIGHT = 80.0f * VRMenuObject::DEFAULT_TEXEL_SCALE; Array< VRMenuSurfaceParms > surfParms; Posef browserButtonPose( Quatf(), UP * ICON_HEIGHT * 2.0f ); comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) ); comps.PushBack( new OvrButton_OnUp( this, ID_BROWSER_BUTTON ) ); comps.PushBack( new OvrSurfaceToggleComponent( ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "apk:///assets/nav_home_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "apk:///assets/nav_home_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); VRMenuObjectParms browserButtonParms( VRMENU_BUTTON, comps, surfParms, "", browserButtonPose, Vector3f( 1.0f ), Posef(), Vector3f( 1.0f ), fontParms, ID_BROWSER_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &browserButtonParms ); AddItems( guiSys, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); surfParms.Clear(); BrowserButtonHandle = attributionObject->ChildHandleForId( guiSys.GetVRMenuMgr(), ID_BROWSER_BUTTON ); VRMenuObject * browserButtonObject = guiSys.GetVRMenuMgr().ToObject( BrowserButtonHandle ); OVR_ASSERT( browserButtonObject != NULL ); OVR_UNUSED( browserButtonObject ); //Video control button Posef videoButtonPose( Quatf(), DOWN * ICON_HEIGHT * 2.0f ); comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) ); comps.PushBack( new OvrButton_OnUp( this, ID_VIDEO_BUTTON ) ); comps.PushBack( new OvrSurfaceToggleComponent( ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "apk:///assets/nav_restart_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "apk:///assets/nav_restart_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); VRMenuObjectParms controlButtonParms( VRMENU_BUTTON, comps, surfParms, "", videoButtonPose, Vector3f( 1.0f ), Posef(), Vector3f( 1.0f ), fontParms, ID_VIDEO_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &controlButtonParms ); AddItems( guiSys, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); VideoControlButtonHandle = attributionObject->ChildHandleForId( guiSys.GetVRMenuMgr(), ID_VIDEO_BUTTON ); VRMenuObject * controlButtonObject = guiSys.GetVRMenuMgr().ToObject( VideoControlButtonHandle ); OVR_ASSERT( controlButtonObject != NULL ); OVR_UNUSED( controlButtonObject ); }
OvrPanoMenu::OvrPanoMenu( App * app, Oculus360Photos * photos, OvrVRMenuMgr & menuMgr, BitmapFont const & font, OvrMetaData & metaData, float fadeOutTime, float radius ) : VRMenu( MENU_NAME ) , AppPtr( app ) , MenuMgr( menuMgr ) , Font( font ) , Photos( photos ) , MetaData( metaData ) , LoadingIconHandle( 0 ) , AttributionHandle( 0 ) , BrowserButtonHandle( 0 ) , SwipeLeftIndicatorHandle( 0 ) , SwipeRightIndicatorHandle( 0 ) , Fader( 1.0f ) , FadeOutTime( fadeOutTime ) , currentFadeRate( 0.0f ) , Radius( radius ) , ButtonCoolDown( 0.0f ) { currentFadeRate = 1.0f / FadeOutTime; // Init with empty root Init( menuMgr, font, 0.0f, VRMenuFlags_t() ); // Create Attribution info view Array< VRMenuObjectParms const * > parms; Array< VRMenuComponent* > comps; VRMenuId_t attributionPanelId( ID_CENTER_ROOT.Get() + 10 ); comps.PushBack( new OvrPanoMenuRootComponent( *this ) ); Quatf rot( DOWN, 0.0f ); Vector3f dir( -FWD ); Posef panelPose( rot, dir * Radius ); Vector3f panelScale( 1.0f ); //const Posef textPose( Quatf(), Vector3f( 0.0f, 0.0f, 0.0f ) ); const VRMenuFontParms fontParms( true, true, false, false, true, 0.525f, 0.45f, 1.0f ); VRMenuObjectParms attrParms( VRMENU_STATIC, comps, VRMenuSurfaceParms(), "Attribution Panel", panelPose, panelScale, Posef(), Vector3f( 1.0f ), fontParms, attributionPanelId, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &attrParms ); AddItems( MenuMgr, Font, parms, GetRootHandle(), false ); parms.Clear(); comps.Clear(); AttributionHandle = HandleForId( MenuMgr, attributionPanelId ); VRMenuObject * attributionObject = MenuMgr.ToObject( AttributionHandle ); OVR_ASSERT( attributionObject != NULL ); //Browser button float const ICON_HEIGHT = 80.0f * VRMenuObject::DEFAULT_TEXEL_SCALE; Array< VRMenuSurfaceParms > surfParms; Posef browserButtonPose( Quatf( ), UP * ICON_HEIGHT * 2.0f ); comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) ); comps.PushBack( new OvrButton_OnUp( this, ID_BROWSER_BUTTON ) ); comps.PushBack( new OvrSurfaceToggleComponent( ) ); surfParms.PushBack( VRMenuSurfaceParms ( "browser", "assets/nav_home_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "browser", "assets/nav_home_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); VRMenuObjectParms browserButtonParms( VRMENU_BUTTON, comps, surfParms, "", browserButtonPose, Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, ID_BROWSER_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &browserButtonParms ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); surfParms.Clear(); BrowserButtonHandle = attributionObject->ChildHandleForId( MenuMgr, ID_BROWSER_BUTTON ); VRMenuObject * browserButtonObject = MenuMgr.ToObject( BrowserButtonHandle ); OVR_ASSERT( browserButtonObject != NULL ); OVR_UNUSED( browserButtonObject ); //Favorites button Posef favoritesButtonPose( Quatf( ), DOWN * ICON_HEIGHT * 2.0f ); comps.PushBack( new OvrDefaultComponent( Vector3f( 0.0f, 0.0f, 0.05f ), 1.05f, 0.25f, 0.0f, Vector4f( 1.0f ), Vector4f( 1.0f ) ) ); comps.PushBack( new OvrButton_OnUp( this, ID_FAVORITES_BUTTON ) ); comps.PushBack( new OvrSurfaceToggleComponent() ); surfParms.PushBack( VRMenuSurfaceParms( "favorites_off", "assets/nav_star_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "favorites_on", "assets/nav_star_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "favorites_active_off", "assets/nav_star_active_off.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); surfParms.PushBack( VRMenuSurfaceParms( "favorites_active_on", "assets/nav_star_active_on.png", SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ) ); VRMenuObjectParms favoritesButtonParms( VRMENU_BUTTON, comps, surfParms, "", favoritesButtonPose, Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, ID_FAVORITES_BUTTON, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_TEXT ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &favoritesButtonParms ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); FavoritesButtonHandle = attributionObject->ChildHandleForId( MenuMgr, ID_FAVORITES_BUTTON ); VRMenuObject * favoritesButtonObject = MenuMgr.ToObject( FavoritesButtonHandle ); OVR_ASSERT( favoritesButtonObject != NULL ); OVR_UNUSED( favoritesButtonObject ); // Swipe icons const int numFrames = 10; const int numTrails = 3; const int numChildren = 5; const float swipeFPS = 3.0f; const float factor = 1.0f / 8.0f; // Right container VRMenuId_t swipeRightId( ID_CENTER_ROOT.Get() + 401 ); Quatf rotRight( DOWN, ( Mathf::TwoPi * factor ) ); Vector3f rightDir( -FWD * rotRight ); comps.PushBack( new OvrTrailsAnimComponent( swipeFPS, true, numFrames, numTrails, numTrails ) ); VRMenuObjectParms swipeRightRoot( VRMENU_CONTAINER, comps, VRMenuSurfaceParms( ), "", Posef( rotRight, rightDir * Radius ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, swipeRightId, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_ALL ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &swipeRightRoot ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); SwipeRightIndicatorHandle = attributionObject->ChildHandleForId( MenuMgr, swipeRightId ); VRMenuObject * swipeRightRootObject = MenuMgr.ToObject( SwipeRightIndicatorHandle ); OVR_ASSERT( swipeRightRootObject != NULL ); // Left container VRMenuId_t swipeLeftId( ID_CENTER_ROOT.Get( ) + 402 ); Quatf rotLeft( DOWN, ( Mathf::TwoPi * -factor ) ); Vector3f leftDir( -FWD * rotLeft ); comps.PushBack( new OvrTrailsAnimComponent( swipeFPS, true, numFrames, numTrails, numTrails ) ); VRMenuObjectParms swipeLeftRoot( VRMENU_CONTAINER, comps, VRMenuSurfaceParms( ), "", Posef( rotLeft, leftDir * Radius ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, swipeLeftId, VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_ALL ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &swipeLeftRoot ); AddItems( MenuMgr, Font, parms, AttributionHandle, false ); parms.Clear(); comps.Clear(); SwipeLeftIndicatorHandle = attributionObject->ChildHandleForId( MenuMgr, swipeLeftId ); VRMenuObject * swipeLeftRootObject = MenuMgr.ToObject( SwipeLeftIndicatorHandle ); OVR_ASSERT( swipeLeftRootObject != NULL ); // Arrow frame children const char * swipeRightIcon = "assets/nav_arrow_right.png"; const char * swipeLeftIcon = "assets/nav_arrow_left.png"; VRMenuSurfaceParms rightIndicatorSurfaceParms( "swipeRightSurface", swipeRightIcon, SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ); VRMenuSurfaceParms leftIndicatorSurfaceParms( "swipeLeftSurface", swipeLeftIcon, SURFACE_TEXTURE_DIFFUSE, NULL, SURFACE_TEXTURE_MAX, NULL, SURFACE_TEXTURE_MAX ); const float surfaceWidth = 25 * VRMenuObject::DEFAULT_TEXEL_SCALE; for ( int i = 0; i < numChildren; ++i ) { //right frame const Vector3f rightPos = ( RIGHT * surfaceWidth * i ) - ( FWD * i * 0.1f ); VRMenuObjectParms swipeRightFrame( VRMENU_STATIC, Array< VRMenuComponent* >(), rightIndicatorSurfaceParms, "", Posef( Quatf( ), rightPos ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, VRMenuId_t( ), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &swipeRightFrame ); AddItems( MenuMgr, Font, parms, SwipeRightIndicatorHandle, false ); parms.Clear(); // left frame const Vector3f leftPos = ( (-RIGHT) * surfaceWidth * i ) - ( FWD * i * 0.1f ); VRMenuObjectParms swipeLeftFrame( VRMENU_STATIC, Array< VRMenuComponent* >(), leftIndicatorSurfaceParms, "", Posef( Quatf( ), leftPos ), Vector3f( 1.0f ), Posef( ), Vector3f( 1.0f ), fontParms, VRMenuId_t( ), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &swipeLeftFrame ); AddItems( MenuMgr, Font, parms, SwipeLeftIndicatorHandle, false ); parms.Clear(); } if ( OvrTrailsAnimComponent* animRightComp = swipeRightRootObject->GetComponentByName< OvrTrailsAnimComponent >( ) ) { animRightComp->Play( ); } if ( OvrTrailsAnimComponent* animLeftComp = swipeLeftRootObject->GetComponentByName< OvrTrailsAnimComponent >( ) ) { animLeftComp->Play( ); } }
//============================== // VRMenuEventHandler::Frame void VRMenuEventHandler::Frame( OvrGuiSys & guiSys, VrFrame const & vrFrame, menuHandle_t const & rootHandle, Posef const & menuPose, Array< VRMenuEvent > & events ) { VRMenuObject * root = guiSys.GetVRMenuMgr().ToObject( rootHandle ); if ( root == NULL ) { return; } // find the object the gaze is touching and update gaze focus const Matrix4f viewMatrix = guiSys.GetApp()->GetLastViewMatrix(); const Vector3f viewPos( GetViewMatrixPosition( viewMatrix ) ); const Vector3f viewFwd( GetViewMatrixForward( viewMatrix ) ); HitTestResult result; menuHandle_t hitHandle = root->HitTest( guiSys, menuPose, viewPos, viewFwd, ContentFlags_t( CONTENT_SOLID ), result ); result.RayStart = viewPos; result.RayDir = viewFwd; VRMenuObject * hit = hitHandle.IsValid() ? guiSys.GetVRMenuMgr().ToObject( hitHandle ) : NULL; /* if ( hit != NULL ) { guiSys.GetApp()->ShowInfoText( 0.0f, "%s", hit->GetText().ToCStr() ); } */ bool focusChanged = ( hitHandle != FocusedHandle ); if ( focusChanged ) { // focus changed VRMenuObject * oldFocus = guiSys.GetVRMenuMgr().ToObject( FocusedHandle ); if ( oldFocus != NULL ) { // setup event for item losing the focus VRMenuEvent event( VRMENU_EVENT_FOCUS_LOST, EVENT_DISPATCH_TARGET, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( hit != NULL ) { if ( ( hit->GetFlags() & VRMENUOBJECT_FLAG_NO_FOCUS_GAINED ) == 0 ) { // set up event for item gaining the focus VRMenuEvent event( VRMENU_EVENT_FOCUS_GAINED, EVENT_DISPATCH_FOCUS, hitHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } } FocusedHandle = hitHandle; } if ( ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_UP ) != 0 ) { VRMenuEvent event( VRMENU_EVENT_SWIPE_UP, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_DOWN ) != 0 ) { VRMenuEvent event( VRMENU_EVENT_SWIPE_DOWN, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_FORWARD ) != 0 ) { VRMenuEvent event( VRMENU_EVENT_SWIPE_FORWARD, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_BACK ) != 0 ) { VRMenuEvent event( VRMENU_EVENT_SWIPE_BACK, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } bool touchPressed = ( vrFrame.Input.buttonPressed & ( BUTTON_TOUCH | BUTTON_A ) ) != 0; bool touchReleased = !touchPressed && ( vrFrame.Input.buttonReleased & ( BUTTON_TOUCH | BUTTON_A ) ) != 0; bool touchDown = ( vrFrame.Input.buttonState & BUTTON_TOUCH ) != 0; // Need to update this for keyboard events as well for ( int i = 0; i < vrFrame.Input.NumKeyEvents; i++ ) { if ( vrFrame.Input.KeyEvents[i].KeyCode == OVR_KEY_RETURN ) { switch ( vrFrame.Input.KeyEvents[i].EventType ) { case KEY_EVENT_DOWN: touchPressed = true; break; case KEY_EVENT_UP: touchReleased = true; break; default: break; } } } /* // report swipe data char const * swipeNames[5] = { "none", "down", "up", "back", "forward" }; int swipeUpDown = ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_UP ) ? 2 : 0; swipeUpDown = ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_DOWN ) ? 1 : swipeUpDown; int swipeForwardBack = ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_FORWARD ) ? 4 : 0; swipeForwardBack = ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_BACK ) ? 3 : swipeForwardBack; guiSys.GetApp()->ShowInfoText( 1.0f, "touch %s\n( %s, %s )\n( %.2f, %.2f )\n( %.2f, %.2f )", touchDown ? swipeNames[1] : swipeNames[2], swipeNames[swipeUpDown], swipeNames[swipeForwardBack], vrFrame.Input.touch[0], vrFrame.Input.touch[1], vrFrame.Input.touchRelative[0], vrFrame.Input.touchRelative[1] ); */ // if nothing is focused, send events to the root if ( touchPressed ) { VRMenuEvent event( VRMENU_EVENT_TOUCH_DOWN, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( touchReleased ) { VRMenuEvent event( VRMENU_EVENT_TOUCH_UP, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( vrFrame.Input.touchRelative, 0.0f ), result ); events.PushBack( event ); } if ( touchDown ) { if ( vrFrame.Input.touchRelative.LengthSq() > Mathf::SmallestNonDenormal ) { VRMenuEvent event( VRMENU_EVENT_TOUCH_RELATIVE, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( vrFrame.Input.touchRelative, 0.0f ), result ); events.PushBack( event ); } VRMenuEvent event( VRMENU_EVENT_TOUCH_ABSOLUTE, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( vrFrame.Input.touch, 0.0f ), result ); events.PushBack( event ); } { // always post the frame event to the root VRMenuEvent event( VRMENU_EVENT_FRAME_UPDATE, EVENT_DISPATCH_BROADCAST, menuHandle_t(), Vector3f( 0.0f ), result ); events.PushBack( event ); } }
void OvrScrollBarComponent::SetScrollFrac( OvrVRMenuMgr & menuMgr, VRMenuObject * self, const float pos ) { if ( NumOfItems <= 0 ) return; // Updating thumb length when pulled beyond its bounds const float scrollEnd = (float)( NumOfItems - 1 ); const float outOfBoundsOffset = 0.5f; const float minThumbLength = ScrollBarCurrentThumbLength * THUMB_SHRINK_FACTOR; const float maxThumbLength = ScrollBarCurrentThumbLength; const float minThumbOffset = 0.0f; const float maxThumbOffset = ( maxThumbLength - minThumbLength ) * 0.5f; float currentThumbLength = ScrollBarCurrentThumbLength; float thumbPosOffset = 0.0f; if ( pos < 0.0f ) { currentThumbLength = LinearRangeMapFloat( pos, -outOfBoundsOffset, 0.0f, minThumbLength, maxThumbLength ); thumbPosOffset = LinearRangeMapFloat( pos, -outOfBoundsOffset, 0.0f, -maxThumbOffset, minThumbOffset ); } else if ( pos > scrollEnd ) { currentThumbLength = LinearRangeMapFloat( pos, scrollEnd + outOfBoundsOffset, scrollEnd, minThumbLength, maxThumbLength ); thumbPosOffset = LinearRangeMapFloat( pos, scrollEnd + outOfBoundsOffset, scrollEnd, maxThumbOffset, minThumbOffset ); } float thumbWidth = ScrollBarThumbWidth; float thumbHeight = ScrollBarThumbHeight; if ( IsVertical ) { thumbHeight = currentThumbLength; } else { thumbWidth = currentThumbLength; } VRMenuObject * thumb = menuMgr.ToObject( self->ChildHandleForId( menuMgr, ScrollBarThumbId ) ); if ( thumb != NULL && NumOfItems > 0 ) { thumb->SetSurfaceDims( 0, Vector2f( thumbWidth, thumbHeight ) ); thumb->RegenerateSurfaceGeometry( 0, false ); } // Updating thumb position float clampedPos = Alg::Clamp( pos, 0.0f, (float)(NumOfItems - 1) ); float thumbPos = LinearRangeMapFloat( clampedPos, 0.0f, (float)(NumOfItems - 1), 0.0f, ( ScrollBarCurrentbaseLength - currentThumbLength ) ); thumbPos -= ( ScrollBarCurrentbaseLength - currentThumbLength ) * 0.5f; thumbPos += thumbPosOffset; thumbPos *= VRMenuObject::DEFAULT_TEXEL_SCALE; if ( thumb != NULL ) { Vector3f direction = RIGHT; if ( IsVertical ) { direction = DOWN; } thumb->SetLocalPosition( ( direction * thumbPos ) - ( FWD * THUMB_FROM_BASE_OFFSET ) ); } }
//============================== // VRMenuEventHandler::Frame void VRMenuEventHandler::Frame( App * app, VrFrame const & vrFrame, OvrVRMenuMgr & menuMgr, BitmapFont const & font, menuHandle_t const & rootHandle,Posef const & menuPose, gazeCursorUserId_t const & gazeUserId, Array< VRMenuEvent > & events ) { VRMenuObject * root = menuMgr.ToObject( rootHandle ); if ( root == NULL ) { return; } // find the object the gaze is touching and update gaze focus const Matrix4f viewMatrix = app->GetLastViewMatrix(); const Vector3f viewPos( GetViewMatrixPosition( viewMatrix ) ); const Vector3f viewFwd( GetViewMatrixForward( viewMatrix ) ); HitTestResult result; menuHandle_t hitHandle = root->HitTest( app, menuMgr, font, menuPose, viewPos, viewFwd, ContentFlags_t( CONTENT_SOLID ), result ); result.RayStart = viewPos; result.RayDir = viewFwd; VRMenuObject * hit = hitHandle.IsValid() ? menuMgr.ToObject( hitHandle ) : NULL; app->GetGazeCursor().UpdateForUser( gazeUserId, result.t, ( hit != NULL && !( hit->GetFlags() & VRMenuObjectFlags_t( VRMENUOBJECT_NO_GAZE_HILIGHT ) ) ) ? CURSOR_STATE_HILIGHT : CURSOR_STATE_NORMAL ); /* if ( hit != NULL ) { app->ShowInfoText( 0.0f, "%s", hit->GetText().ToCStr() ); } */ bool focusChanged = ( hitHandle != FocusedHandle ); if ( focusChanged ) { // focus changed VRMenuObject * oldFocus = menuMgr.ToObject( FocusedHandle ); if ( oldFocus != NULL ) { // setup event for item losing the focus VRMenuEvent event( VRMENU_EVENT_FOCUS_LOST, EVENT_DISPATCH_TARGET, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( hit != NULL ) { if ( ( hit->GetFlags() & VRMENUOBJECT_FLAG_NO_FOCUS_GAINED ) == 0 ) { // set up event for item gaining the focus VRMenuEvent event( VRMENU_EVENT_FOCUS_GAINED, EVENT_DISPATCH_FOCUS, hitHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } } FocusedHandle = hitHandle; } bool touchPressed = ( vrFrame.Input.buttonPressed & ( BUTTON_TOUCH | BUTTON_A ) ) != 0; bool touchReleased = !touchPressed && ( vrFrame.Input.buttonReleased & ( BUTTON_TOUCH | BUTTON_A ) ) != 0; bool touchDown = ( vrFrame.Input.buttonState & BUTTON_TOUCH ) != 0; if ( ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_UP ) != 0 ) { VRMenuEvent event( VRMENU_EVENT_SWIPE_UP, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_DOWN ) != 0 ) { VRMenuEvent event( VRMENU_EVENT_SWIPE_DOWN, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_FORWARD ) != 0 ) { VRMenuEvent event( VRMENU_EVENT_SWIPE_FORWARD, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_BACK ) != 0 ) { VRMenuEvent event( VRMENU_EVENT_SWIPE_BACK, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } /* // report swipe data char const * swipeNames[5] = { "none", "down", "up", "back", "forward" }; int swipeUpDown = ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_UP ) ? 2 : 0; swipeUpDown = ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_DOWN ) ? 1 : swipeUpDown; int swipeForwardBack = ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_FORWARD ) ? 4 : 0; swipeForwardBack = ( vrFrame.Input.buttonPressed & BUTTON_SWIPE_BACK ) ? 3 : swipeForwardBack; app->ShowInfoText( 1.0f, "touch %s\n( %s, %s )\n( %.2f, %.2f )\n( %.2f, %.2f )", touchDown ? swipeNames[1] : swipeNames[2], swipeNames[swipeUpDown], swipeNames[swipeForwardBack], vrFrame.Input.touch[0], vrFrame.Input.touch[1], vrFrame.Input.touchRelative[0], vrFrame.Input.touchRelative[1] ); */ // if nothing is focused, send events to the root if ( touchPressed ) { VRMenuEvent event( VRMENU_EVENT_TOUCH_DOWN, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( 0.0f ), result ); events.PushBack( event ); } if ( touchReleased ) { VRMenuEvent event( VRMENU_EVENT_TOUCH_UP, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( vrFrame.Input.touchRelative, 0.0f ), result ); events.PushBack( event ); } if ( touchDown ) { if ( vrFrame.Input.touchRelative.LengthSq() > Mathf::SmallestNonDenormal ) { VRMenuEvent event( VRMENU_EVENT_TOUCH_RELATIVE, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( vrFrame.Input.touchRelative, 0.0f ), result ); events.PushBack( event ); } VRMenuEvent event( VRMENU_EVENT_TOUCH_ABSOLUTE, EVENT_DISPATCH_FOCUS, FocusedHandle, Vector3f( vrFrame.Input.touch, 0.0f ), result ); events.PushBack( event ); } { // always post the frame event to the root VRMenuEvent event( VRMENU_EVENT_FRAME_UPDATE, EVENT_DISPATCH_BROADCAST, menuHandle_t(), Vector3f( 0.0f ), result ); events.PushBack( event ); } }
void ResumeMovieView::CreateMenu( App * app, OvrVRMenuMgr & menuMgr, BitmapFont const & font ) { Menu = VRMenu::Create( "ResumeMoviePrompt" ); Vector3f fwd( 0.0f, 0.0f, 1.0f ); Vector3f up( 0.0f, 1.0f, 0.0f ); Vector3f defaultScale( 1.0f ); Array< VRMenuObjectParms const * > parms; VRMenuFontParms fontParms( true, true, false, false, false, 1.3f ); Quatf orientation( Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ); Vector3f centerPos( 0.0f, 0.0f, 0.0f ); VRMenuObjectParms centerRootParms( VRMENU_CONTAINER, Array< VRMenuComponent* >(), VRMenuSurfaceParms(), "CenterRoot", Posef( orientation, centerPos ), Vector3f( 1.0f, 1.0f, 1.0f ), fontParms, ID_CENTER_ROOT, VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( ¢erRootParms ); Menu->InitWithItems( menuMgr, font, 0.0f, VRMenuFlags_t(), parms ); parms.Clear(); // the centerroot item will get touch relative and touch absolute events and use them to rotate the centerRoot menuHandle_t centerRootHandle = Menu->HandleForId( menuMgr, ID_CENTER_ROOT ); VRMenuObject * centerRoot = menuMgr.ToObject( centerRootHandle ); OVR_ASSERT( centerRoot != NULL ); // ============================================================================== // // title // { Posef panelPose( Quatf( up, 0.0f ), Vector3f( 0.0f, 2.2f, -3.0f ) ); VRMenuObjectParms p( VRMENU_STATIC, Array< VRMenuComponent* >(), VRMenuSurfaceParms(), Strings::ResumeMenu_Title, panelPose, defaultScale, fontParms, VRMenuId_t( ID_TITLE.Get() ), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( &p ); Menu->AddItems( menuMgr, font, parms, centerRootHandle, false ); parms.Clear(); } // ============================================================================== // // options // Array<const char *> options; options.PushBack( Strings::ResumeMenu_Resume ); options.PushBack( Strings::ResumeMenu_Restart ); Array<const char *> icons; icons.PushBack( "assets/resume.png" ); icons.PushBack( "assets/restart.png" ); Array<PanelPose> optionPositions; optionPositions.PushBack( PanelPose( Quatf( up, 0.0f / 180.0f * Mathf::Pi ), Vector3f( -0.5f, 1.7f, -3.0f ), Vector4f( 1.0f, 1.0f, 1.0f, 1.0f ) ) ); optionPositions.PushBack( PanelPose( Quatf( up, 0.0f / 180.0f * Mathf::Pi ), Vector3f( 0.5f, 1.7f, -3.0f ), Vector4f( 1.0f, 1.0f, 1.0f, 1.0f ) ) ); int borderWidth = 0, borderHeight = 0; GLuint borderTexture = LoadTextureFromApplicationPackage( "assets/resume_restart_border.png", TextureFlags_t( TEXTUREFLAG_NO_DEFAULT ), borderWidth, borderHeight ); for ( int i = 0; i < optionPositions.GetSizeI(); ++i ) { ResumeMovieComponent * resumeMovieComponent = new ResumeMovieComponent( this, i ); Array< VRMenuComponent* > optionComps; optionComps.PushBack( resumeMovieComponent ); VRMenuSurfaceParms panelSurfParms( "", borderTexture, borderWidth, borderHeight, SURFACE_TEXTURE_ADDITIVE, 0, 0, 0, SURFACE_TEXTURE_MAX, 0, 0, 0, SURFACE_TEXTURE_MAX ); Posef panelPose( optionPositions[ i ].Orientation, optionPositions[ i ].Position ); VRMenuObjectParms * p = new VRMenuObjectParms( VRMENU_BUTTON, optionComps, panelSurfParms, options[ i ], panelPose, defaultScale, fontParms, VRMenuId_t( ID_OPTIONS.Get() + i ), VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( p ); Menu->AddItems( menuMgr, font, parms, centerRootHandle, false ); DeletePointerArray( parms ); parms.Clear(); // add icon menuHandle_t optionHandle = centerRoot->ChildHandleForId( menuMgr, VRMenuId_t( ID_OPTIONS.Get() + i ) ); VRMenuObject * optionObject = menuMgr.ToObject( optionHandle ); OVR_ASSERT( optionObject != NULL ); int iconWidth = 0, iconHeight = 0; GLuint iconTexture = LoadTextureFromApplicationPackage( icons[ i ], TextureFlags_t( TEXTUREFLAG_NO_DEFAULT ), iconWidth, iconHeight ); VRMenuSurfaceParms iconSurfParms( "", iconTexture, iconWidth, iconHeight, SURFACE_TEXTURE_DIFFUSE, 0, 0, 0, SURFACE_TEXTURE_MAX, 0, 0, 0, SURFACE_TEXTURE_MAX ); Bounds3f textBounds = optionObject->GetTextLocalBounds( font ); optionObject->SetTextLocalPosition( Vector3f( iconWidth * VRMenuObject::DEFAULT_TEXEL_SCALE * 0.5f, 0.0f, 0.0f ) ); Posef iconPose( optionPositions[ i ].Orientation, optionPositions[ i ].Position + Vector3f( textBounds.GetMins().x, 0.0f, 0.01f ) ); p = new VRMenuObjectParms( VRMENU_STATIC, Array< VRMenuComponent* >(), iconSurfParms, NULL, iconPose, defaultScale, fontParms, VRMenuId_t( ID_OPTION_ICONS.Get() + i ), VRMenuObjectFlags_t( VRMENUOBJECT_DONT_HIT_ALL ), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) ); parms.PushBack( p ); Menu->AddItems( menuMgr, font, parms, centerRootHandle, false ); DeletePointerArray( parms ); parms.Clear(); menuHandle_t iconHandle = centerRoot->ChildHandleForId( menuMgr, VRMenuId_t( ID_OPTION_ICONS.Get() + i ) ); resumeMovieComponent->Icon = menuMgr.ToObject( iconHandle ); } Cinema.app->GetGuiSys().AddMenu( Menu ); }