コード例 #1
0
        public void TestCtor()
        {
            // Define variables and constants
            const ViewportAnchoring TEST_ANCHORING = ViewportAnchoring.BottomRight;
            Vector2     testAnchorOffset           = new Vector2(0.3f, 0.4f);
            Vector2     testSize        = new Vector2(0.6f, 0.5f);
            const float TEST_NEAR_PLANE = 0.1f;
            const float TEST_FAR_PLANE  = 1000f;

            Window testWindow = new Window("VP Test Window");

            testWindow.ClearViewports();
            SceneViewport testViewport = testWindow.AddViewport(TEST_ANCHORING, testAnchorOffset, testSize, TEST_NEAR_PLANE, TEST_FAR_PLANE);

            // Set up context


            // Execute


            // Assert outcome
            Assert.AreEqual(TEST_ANCHORING, testViewport.Anchoring);
            Assert.AreEqual(testAnchorOffset, testViewport.AnchorOffset);
            Assert.AreEqual(testSize, testViewport.Size);
            Assert.AreEqual(TEST_NEAR_PLANE, testViewport.NearPlaneDist);
            Assert.AreEqual(TEST_FAR_PLANE, testViewport.FarPlaneDist);

            testWindow.Close();
        }
コード例 #2
0
 /// <summary>
 /// Adds a new <see cref="SceneViewport"/> to this window.
 /// </summary>
 /// <remarks>
 /// All newly-created Windows have a default viewport that occupies their entirety added when they are created.
 /// Therefore, there is no need to add a viewport unless you wish to override this default configuration.
 /// </remarks>
 /// <param name="anchoring">The side or corner of this viewport that retains its relative position when this window is resized.
 /// See also: <see cref="SceneViewport.Anchoring"/>.</param>
 /// <param name="anchorOffset">The offset from the anchored corner or side of the window that this viewport resides at.
 /// Both the <see cref="Vector2.X"/> and <see cref="Vector2.Y"/> values must be in the range <c>0f</c> to <c>1f</c>, where
 /// <c>0f</c> indicates an offset of 0%, and <c>1f</c> indicates an offset of <c>100%</c>.
 /// See also: <see cref="SceneViewport.AnchorOffset"/>.</param>
 /// <param name="size">The size of this viewport, specified as a ratio of the window's resolution.
 /// Both the <see cref="Vector2.X"/> and <see cref="Vector2.Y"/> values must be in the range <c>0f</c> to <c>1f</c>, where
 /// <c>0f</c> indicates a size of 0%, and <c>1f</c> indicates a size of <c>100%</c>.
 /// The combination of size and <paramref name="anchorOffset"/> in either dimension must not exceed 100% (<c>1f</c>).
 /// See also: <see cref="SceneViewport.Size"/>.</param>
 /// <param name="nearPlaneDist">The minimum distance between any object and the <see cref="Camera"/>
 /// rendering to this viewport permissible for an object to be drawn.</param>
 /// <param name="farPlaneDist">The maximum distance between any object and the <see cref="Camera"/>
 /// rendering to this viewport permissible for an object to be drawn.</param>
 /// <returns>The newly created viewport that has been added to this window.</returns>
 public SceneViewport AddViewport(ViewportAnchoring anchoring, Vector2 anchorOffset, Vector2 size,
                                  float nearPlaneDist = 0.1f, float farPlaneDist = 1000f)
 {
     lock (WindowMutationLock) {
         SceneViewport result = new SceneViewport(this, anchoring, anchorOffset, size, nearPlaneDist, farPlaneDist);
         addedViewports.Add(result);
         return(result);
     }
 }
コード例 #3
0
        internal FontString(Font font, SceneLayer sceneLayer, SceneViewport viewport, ViewportAnchoring anchoring, Vector2 anchorOffset, Vector2 scale)
        {
            this.sceneLayer         = sceneLayer;
            this.viewport           = viewport;
            this.anchoring          = anchoring;
            this.anchorOffset       = anchorOffset;
            this.scale              = scale;
            this.font               = font;
            this.createMaterialFunc = CreateNewMaterial;

            viewport.TargetWindow.WindowResized += ResizeText;
        }
コード例 #4
0
        // No lock on WindowTarget.WindowMutationLock here because it's an internal method, only accessible from Window.AddViewport.
        // If that changes in the future, add a lock!
        internal SceneViewport(Window targetWindow, ViewportAnchoring anchoring, Vector2 anchorOffset, Vector2 size,
                               float nearPlaneDist, float farPlaneDist)
        {
            if (targetWindow == null)
            {
                throw new ArgumentNullException("targetWindow");
            }
            if (!Enum.IsDefined(typeof(ViewportAnchoring), anchoring))
            {
                throw new ArgumentException("Invalid enum value.", "anchoring");
            }
            //if (anchorOffset.X < 0f || anchorOffset.X > 1f || anchorOffset.Y < 0f || anchorOffset.Y > 1f) {
            //	throw new ArgumentException("Both anchor offset dimensions must be between 0f and 1f.", "anchorOffset");
            //}
            //if (size.X < 0f || size.X > 1f - anchorOffset.X || size.Y < 0f || size.Y > 1f - anchorOffset.Y) {
            //	throw new ArgumentException("combination of size and anchor offset in either dimension must be between 0f and 1f.", "size");
            //}
            if (nearPlaneDist <= 0f)
            {
                throw new ArgumentException("Near plane must be greater than 0f.", "nearPlaneDist");
            }
            if (farPlaneDist <= 0f)
            {
                throw new ArgumentException("Far plane must be greater than 0f.", "farPlaneDist");
            }

            this.TargetWindow  = targetWindow;
            this.Anchoring     = anchoring;
            this.AnchorOffset  = anchorOffset;
            this.Size          = size;
            this.NearPlaneDist = nearPlaneDist;
            this.FarPlaneDist  = farPlaneDist;

            if (targetWindow.IsClosed)
            {
                ViewportHandle = ViewportHandle.NULL;
                isDisposed     = true;
            }
            else
            {
                ViewportHandle outViewportHandle;
                unsafe {
                    InteropUtils.CallNative(NativeMethods.WindowFactory_CreateViewport,
                                            (IntPtr)(&outViewportHandle)
                                            ).ThrowOnFailure();
                }
                ViewportHandle = outViewportHandle;
            }

            TargetWindow_WindowResized(TargetWindow, TargetWindow.Width, TargetWindow.Height);
            TargetWindow.WindowResized += TargetWindow_WindowResized;
        }
コード例 #5
0
ファイル: Font.cs プロジェクト: dawsonzhangwei/EscapeLizards
        public FontString AddString(SceneLayer sceneLayer, SceneViewport viewport,
                                    ViewportAnchoring anchoring, Vector2 anchorOffset, Vector2 scale)
        {
            lock (instanceMutationLock) {
                Assure.NotNull(sceneLayer);
                Assure.False(sceneLayer.IsDisposed);
                Assure.NotNull(viewport);
                Assure.False(viewport.IsDisposed);
                if (isDisposed)
                {
                    throw new ObjectDisposedException(Name);
                }

                return(new FontString(this, sceneLayer, viewport, anchoring, anchorOffset, scale));
            }
        }