/// <summary> /// Show the Toast widget with an animated fade in. The widget will fade out /// after Duration seconds, unless the user hovers over it, in which case it /// will stay until they end the hover. /// </summary> public void Show(Cockpit cockpit, float fDuration, float fFadeInOut = 0.25f) { AlphaFade = 0.0f; hovering = false; disappear = false; // if this goes true, toast will begin animated-fade on next frame dismiss = false; // we register a basic animator that just watches for dismiss=true and // when that happens we fade out and remove the toast cockpit.HUDAnimator.Register( new GenericAnimatable(() => { if (dismiss) { HUDUtil.AnimatedDimiss_Cockpit(this, cockpit, (disappear) ? 0.001f : fFadeInOut); dismiss_timer.Dispose(); return(true); } return(false); }) ); // timer event that is called after the initial duration, and then ever // couple hundred MS to check that hover ended. // This is called from a Timer, which runs in a separate thread, and hence // we cannot manipulate the scene in this function // TODO: couldn't we just do this in animator above?? Action timer_elapsed = () => { if (hovering) { dismiss_timer.Interval = 300; dismiss_timer.Start(); } else { dismiss = true; } }; // ok, this kicks everything off - we do animated transition to show ourself, // and then start a timer that waits the initial duration HUDUtil.AnimatedShow(this, fFadeInOut, () => { dismiss_timer = new Timer(fDuration * 1000); dismiss_timer.Elapsed += (o, e) => { timer_elapsed(); }; dismiss_timer.Enabled = true; }); }
void add(HUDStandardItem element, LayoutOptions options) { if (element.IsVisible == false) { element.IsVisible = true; } IBoxModelElement elemBoxModel = element as IBoxModelElement; // for 2D view (but doesn't matter if we are doing a layout anyway!) Frame3f viewFrame = Cockpit.GetViewFrame2D(); // with 3D view we should use this... //Frame3f viewFrame = Frame3f.Identity; element.SetObjectFrame(Frame3f.Identity); HUDUtil.PlaceInViewPlane(element, viewFrame); Cockpit.AddUIElement(element); Func <Vector2f> pinSourceF = options.PinSourcePoint2D; if (pinSourceF == null) { pinSourceF = LayoutUtil.BoxPointF(elemBoxModel, BoxPosition.Center); } Func <Vector2f> pinTargetF = options.PinTargetPoint2D; if (pinTargetF == null) { pinTargetF = LayoutUtil.BoxPointF(Solver.Container, BoxPosition.Center); } Solver.AddLayoutItem(element, pinSourceF, pinTargetF, this.StandardDepth + options.DepthShift); // if we want to shift result in its layout frame, do that via a post-transform if (options.FrameAxesShift != Vector3f.Zero) { Solver.AddPostTransform(element, (e) => { Frame3f f = (e as IElementFrame).GetObjectFrame(); f.Translate(options.FrameAxesShift.x * f.X + options.FrameAxesShift.y * f.Y + options.FrameAxesShift.z * f.Z); (e as IElementFrame).SetObjectFrame(f); }); } // auto-show if ((options.Flags & LayoutFlags.AnimatedShow) != 0) { HUDUtil.AnimatedShow(element); } }
void add(HUDStandardItem element, LayoutOptions options) { if (element.IsVisible == false) { element.IsVisible = true; } IBoxModelElement elemBoxModel = element as IBoxModelElement; // for 2D view (but doesn't matter if we are doing a layout anyway!) Frame3f viewFrame = Cockpit.GetViewFrame2D(); // with 3D view we should use this... //Frame3f viewFrame = Frame3f.Identity; element.SetObjectFrame(Frame3f.Identity); HUDUtil.PlaceInViewPlane(element, viewFrame); Cockpit.AddUIElement(element); Func <Vector2f> pinSourceF = options.PinSourcePoint2D; if (pinSourceF == null) { pinSourceF = LayoutUtil.BoxPointF(elemBoxModel, BoxPosition.Center); } Func <Vector2f> pinTargetF = options.PinTargetPoint2D; if (pinTargetF == null) { pinTargetF = LayoutUtil.BoxPointF(Solver.Container, BoxPosition.Center); } Solver.AddLayoutItem(element, pinSourceF, pinTargetF, this.StandardDepth + options.DepthShift); // auto-show if ((options.Flags & LayoutFlags.AnimatedShow) != 0) { HUDUtil.AnimatedShow(element); } }