コード例 #1
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            #if DEBUG
            Profiler.Instance.StartBlock("GUIText.OnRender");
            #endif

            DrawUtil.ClearBitmapModulation();

            ctrlRect = new RectangleF(offset, _bounds.Extent);

            // fill the update rect with the fill color
            if (_style.IsOpaque)
                DrawUtil.RectFill(ctrlRect, _style.FillColor[CustomColor.ColorBase]);

            // if there's a border, draw the border
            if (_style.HasBorder)
                DrawUtil.Rect(ctrlRect, _style.BorderColor[CustomColor.ColorBase]);

            DrawUtil.JustifiedText(_style.Font, new Vector2(offset.X - updateRect.Point.X, offset.Y - updateRect.Point.Y), _bounds.Extent, _style.Alignment, _style.TextColor[CustomColor.ColorBase], _text);

            #if DEBUG
            Profiler.Instance.EndBlock("GUIText.OnRender");
            #endif

            // render the child controls
            _RenderChildControls(offset, updateRect);
        }
コード例 #2
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            if (fadeColour.A > 150)
            {
                fadeColour.A -= 1;
                Style.FillColor[CustomColor.ColorBase] = fadeColour;
            }

            base.OnRender(offset, updateRect);
        }
コード例 #3
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            if (!displayTimer.Running && !displayTimer.Expired)
                displayTimer.Start();
            else if (displayTimer.Expired)
            {
                displayTimer.Reset();
                this.MarkForDelete = true;
            }

            base.OnRender(offset, updateRect);
        }
コード例 #4
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            if (fadeColour.A > 150)
            {
                fadeColour.A -= 1;
                Style.FillColor[CustomColor.ColorBase] = fadeColour;
            }
            else
            {
                currentScene = Game.Instance.SceneLoader.Load(@"data\levels\Level1.txscene");
                Game.Instance.SetCurrentScene(currentScene);
                GUICanvas.Instance.PopDialogControl(this);
                SoundManager.Instance.StopAllCues();
                SoundManager.Instance.PlaySound("music", "level 1");
            }

            base.OnRender(offset, updateRect);
        }
コード例 #5
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            #if DEBUG
            Profiler.Instance.StartBlock("GUIMLText.OnRender");
            #endif

            DrawUtil.ClearBitmapModulation();

            RectangleF ctrlRect = new RectangleF(offset, _bounds.Extent);

            // fill the update rect with the fill color
            if (_style.IsOpaque)
                DrawUtil.RectFill(ctrlRect, _style.FillColor[CustomColor.ColorBase]);

            // if there's a border, draw the border
            if (_style.HasBorder)
                DrawUtil.Rect(ctrlRect, _style.BorderColor[CustomColor.ColorBase]);

            if (_splitText != null)
            {
                Vector2 pos = offset - updateRect.Point;
                Vector2 size = new Vector2(Bounds.Width, _style.Font.Instance.LineSpacing + _style.LineSpacing);
                for (int i = 0; i < _splitText.Length; i++)
                {
                    DrawUtil.JustifiedText(_style.Font, pos, size, _style.Alignment, _style.TextColor[CustomColor.ColorBase], _splitText[i]);
                    pos.Y += size.Y;
                }
            }

            #if DEBUG
            Profiler.Instance.EndBlock("GUIMLText.OnRender");
            #endif

            // render the child controls
            _RenderChildControls(offset, updateRect);
        }
コード例 #6
0
 /// <summary>
 /// Tests if this rectangle overlaps another rectangle.
 /// </summary>
 /// <param name="rect">The rectangle to test against.</param>
 /// <returns></returns>
 public bool Overlaps(RectangleF rect)
 {
     RectangleF test = new RectangleF(this);
     return test.Intersect(rect);
 }
コード例 #7
0
 /// <summary>
 /// Extend the rectangle so that it contains another rectangle.
 /// </summary>
 /// <param name="rect">The rectangle to envelop.</param>
 public void Union(RectangleF rect)
 {
     Union(rect._point);
     Union(rect._point + rect._extent);
 }
コード例 #8
0
        /// <summary>
        /// Set this rectangle to the intersection of it and another rectangle.
        /// </summary>
        /// <param name="clipRect">The rectangle to intersect with.</param>
        /// <returns>Whether or not the resulting rectangle is valid.</returns>
        public bool Intersect(RectangleF clipRect)
        {
            Vector2 bottomL;
            bottomL.X = MathHelper.Min(_point.X + _extent.X, clipRect.Point.X + clipRect.Extent.X);
            bottomL.Y = MathHelper.Min(_point.Y + _extent.Y, clipRect.Point.Y + clipRect.Extent.Y);

            _point.X = MathHelper.Max(_point.X, clipRect.Point.X);
            _point.Y = MathHelper.Max(_point.Y, clipRect.Point.Y);

            _extent.X = bottomL.X - _point.X;
            _extent.Y = bottomL.Y - _point.Y;

            return IsValid;
        }
コード例 #9
0
        /// <summary>
        /// Returns whether or not this rectangle intersects with another rectangle.
        /// </summary>
        /// <param name="rect">The rectangle to test intersections with.</param>
        /// <returns>True if the rectangles intersect.</returns>
        public bool IntersectsWith(RectangleF rect)
        {
            if (_point.X + _extent.X < rect._point.X)
                return false;

            if (_point.Y + _extent.Y < rect._point.Y)
                return false;

            if (rect._point.X + rect._extent.X < _point.X)
                return false;

            if (rect._point.Y + rect._extent.Y < _point.Y)
                return false;

            return true;
        }
コード例 #10
0
        protected override void _RenderObjects(TorqueObjectType renderMask, float aspectRatio)
        {
            // clear results from previous container query
            _containerQueryResults.Clear();

            // find objects to render
            RectangleF sceneRect = new RectangleF(_t2dCamera.SceneMin.X, _t2dCamera.SceneMin.Y, _t2dCamera.SceneMax.X - _t2dCamera.SceneMin.X, _t2dCamera.SceneMax.Y - _t2dCamera.SceneMin.Y);
            FindObjects(sceneRect, renderMask, 0xFFFFFFFF, _containerQueryResults);

            // sort by layer
            if (_useLayerSorting && _containerQueryResults.Count > 0)
            {
                _containerQueryResults.Sort(T2DLayerSortDictionary.LayerSort);

                // sort contents of each layer
                int start = 0;
                int lastLayer = (_containerQueryResults[0] as ISceneObject2D).Layer;
                for (int end = 0; end < _containerQueryResults.Count; end++)
                {
                    ISceneObject2D sceneObject = _containerQueryResults[end] as ISceneObject2D;
                    int layer = sceneObject.Layer;

                    // We reached the last object in a layer, or, the end of the
                    // list. Sort this subsection.
                    if (layer == lastLayer && end < _containerQueryResults.Count - 1)
                        continue;

                    IComparer<ISceneContainerObject> comparer = null;
                    if (!_layerSortDictionary.TryGetValue(lastLayer, out comparer) || comparer == null)
                        comparer = T2DLayerSortDictionary.DefaultSort;

                    if (comparer != T2DLayerSortDictionary.NoSort && (end - start) > 1)
                        _containerQueryResults.Sort(start, end - start, comparer);

                    start = end;
                    lastLayer = layer;
                }
            }

            if (!_useDepthBuffer)
                SceneRenderer.RenderManager.BinOverride = RenderInstance.RenderInstanceType.Mesh2D;

            // Number of objects we are about to render.
            int count = _containerQueryResults.Count;

            // This is the greatest depth value that will still be render as within
            // the camera frustum. Because the objects LayerDepth is a world
            // space value we must account for any camera offset in z.
            float maxDepth = _t2dCamera.FarDistance - _t2dCamera.Transform.Translation.Z;

            // If the FarDistance happens to be rediculously close, lets at
            // least not crash.
            if (maxDepth <= 0.0f)
                maxDepth = 1.0f;

            // Give each object a sliver of our available depth.
            // Given enough objects it is still possible to have z-fighting
            // but this is better than losing objects by pushing them past the FarDistance.
            float step = -maxDepth / (float)count;

            for (int i = 0; i < count; i++)
            {
                ISceneObject2D sceneObject = _containerQueryResults[i] as ISceneObject2D;
                sceneObject.LayerDepth = _useLayerSorting ? step * (float)i : -(float)sceneObject.Layer;
                _containerQueryResults[i].Render(_srs);
            }

            SceneRenderer.RenderManager.BinOverride = RenderInstance.RenderInstanceType.UndefinedType;
        }
コード例 #11
0
        private void _UpdateRenderQuad(RectangleF texCoords, RectangleF verts)
        {
            VertexPositionTexture[] v = TorqueUtil.GetScratchArray<VertexPositionTexture>(4);
            Int32 idx = 0;

            for (Int32 ix = 0; ix < 2; ix++)
                for (Int32 iy = 0; iy < 2; iy++)
                    v[idx++] = new VertexPositionTexture(new Vector3(((float)ix * verts.Width) + verts.X, ((float)iy * verts.Height) + verts.Y, 0),
                                                        new Vector2(((float)ix * texCoords.Width) + texCoords.X, ((float)iy * texCoords.Height) + texCoords.Y));

            GFXDevice.Instance.Device.Vertices[0].SetSource(null, 0, 0);
            v.CopyTo(_renderQuadVB, 0);
        }
コード例 #12
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            #if DEBUG
            Profiler.Instance.StartBlock("GUIVideo.OnRender");
            #endif

            if (_material.IsStopped)
            {
                if (_onVideoEnd != null)
                {
                    if (!_onVideoEnd.Invoke(VideoFilename))
                    {
                        _onVideoEnd = null;
            #if DEBUG
                        Profiler.Instance.EndBlock("GUIVideo.OnRender");
            #endif
                        return;
                    }
                    _onVideoEnd = null;
                }
            }

            // clear bitmap modulation
            DrawUtil.ClearBitmapModulation();

            RectangleF ctrlRect = new RectangleF(offset, _bounds.Extent);

            // fill in, if appropriate
            if (_style.IsOpaque)
                DrawUtil.RectFill(ctrlRect, _style.FillColor[CustomColor.ColorBase]);

            // set the opacity of the material
            _material.Opacity = _opacity;

            if (_material != null)
            {
                // draw the bitmap
                DrawUtil.BitmapStretch(_material, ctrlRect, BitmapFlip.None);
            }

            // draw a border, if appropriate
            if (_style.HasBorder)
                DrawUtil.Rect(ctrlRect, _style.BorderColor[CustomColor.ColorBase]);

            #if DEBUG
            Profiler.Instance.EndBlock("GUIVideo.OnRender");
            #endif

            // render the child controls
            _RenderChildControls(offset, updateRect);
        }
コード例 #13
0
        public override void Render(SceneRenderState srs)
        {
            #if DEBUG
            Profiler.Instance.StartBlock("T2DAnimatedSprite.Render");
            #endif

            // call base render
            base.Render(srs);

            // do not render if the data doesn't exist
            if (_animationData == null)
            {
            #if DEBUG
                Profiler.Instance.EndBlock("T2DAnimatedSprite.Render");
            #endif
                return;
            }

            // make sure the animation data has been interpreted
            if (_animationDataDirty)
                _InterpretAnimationData();

            // make sure we have a material assigned
            if (_quad.Material == null)
            {
            #if DEBUG
                Profiler.Instance.EndBlock("T2DAnimatedSprite.Render");
            #endif
                return;
            }

            // check if we need to update our current frame area
            if (_currentFrameAreaDirty)
                _currentFrameArea = _animationData.AnimationFramesList[_ac.CurrentFrame];

            _quad.SetupUVs(_currentFrameArea, FlipX, FlipY);

            Vector3 ScaleVector = new Vector3(0.5f * Size.X, 0.5f * Size.Y, 1);

            Matrix objToWorld = Matrix.Identity;

            // scale
            Matrix ScaleMatrix = Matrix.CreateScale(ScaleVector);

            // translate
            Matrix TranslationMatrix = Matrix.CreateTranslation(new Vector3(Position.X, Position.Y, LayerDepth));

            // rotate
            Matrix RotationMatrix = Matrix.CreateRotationZ(MathHelper.ToRadians(Rotation));

            objToWorld = ScaleMatrix * RotationMatrix * TranslationMatrix;

            // forward to quad
            _quad.Render(objToWorld, VisibilityLevel, srs);

            #if DEBUG
            Profiler.Instance.EndBlock("T2DAnimatedSprite.Render");
            #endif
        }
コード例 #14
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            // adltodo: render scroll bars.

            #if DEBUG
            Profiler.Instance.StartBlock("GUIScroll.OnRender");
            #endif

            DrawUtil.ClearBitmapModulation();

            RectangleF ctrlRect = new RectangleF(offset, _bounds.Extent);

            // fill the update rect with the fill color
            if (Style.IsOpaque)
                DrawUtil.RectFill(ctrlRect, Style.FillColor[CustomColor.ColorBase]);

            // if there's a border, draw the border
            if (Style.HasBorder)
                DrawUtil.Rect(ctrlRect, Style.BorderColor[CustomColor.ColorBase]);

            if (VScrollVisible)
            {
                RectangleF vScrollRect = ctrlRect;
                vScrollRect.X += ctrlRect.Width - _scrollBarWidth;
                vScrollRect.Width = _scrollBarWidth;
                vScrollRect.Height -= _scrollBarWidth;

                //DrawUtil.Rect(vScrollRect, new Microsoft.Xna.Framework.Graphics.Color(255, 0, 0));
            }

            if (HScrollVisible)
            {
                RectangleF hScrollRect = ctrlRect;
                hScrollRect.Y += ctrlRect.Height - _scrollBarWidth;
                hScrollRect.Width -= _scrollBarWidth;
                hScrollRect.Height = _scrollBarWidth;
                //DrawUtil.Rect(hScrollRect, new Microsoft.Xna.Framework.Graphics.Color(255, 0, 0));
            }

            // render the child controls
            RectangleF childUpdateRect = updateRect;

            if (VScrollVisible)
                childUpdateRect.Width -= _scrollBarWidth;

            if (HScrollVisible)
                childUpdateRect.Height -= _scrollBarWidth;

            #if DEBUG
            Profiler.Instance.EndBlock("GUIScroll.OnRender");
            #endif

            _RenderChildControls(offset + _childOffset, childUpdateRect);
        }
コード例 #15
0
        private void _UpdateBounds()
        {
            Vector2 upperRight = new Vector2(0.0f, 0.0f);
            Vector2 lowerRight = new Vector2(0.0f, 0.0f);

            int numObjects = GetNumObjects();

            for (int idx = 0; idx < numObjects; idx++)
            {
                GUIControl child = (GUIControl)GetObject(idx);
                if (child == null)
                    continue;

                Vector2 childLowerRight = child.Position + child.Bounds.Extent;

                if (childLowerRight.X > lowerRight.X)
                    lowerRight.X = childLowerRight.X;

                if (childLowerRight.Y > lowerRight.Y)
                    lowerRight.Y = childLowerRight.Y;
            }

            _childBounds = new RectangleF(upperRight, lowerRight - upperRight);
        }
コード例 #16
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            #if DEBUG
            Profiler.Instance.StartBlock("GUISplash.OnRender");
            #endif

            // clear bitmap modulation
            DrawUtil.ClearBitmapModulation();

            if (_style.Bitmap != null)
            {
                // draw the bitmap
                RectangleF rect = new RectangleF(offset, _bounds.Extent);
                DrawUtil.BitmapStretch(_style.Material, rect, BitmapFlip.None);
            }

            // draw the fade quad
            Color fadeColor = new Color(0, 0, 0, _currentAlpha);
            DrawUtil.RectFill(offset, _bounds.Extent + offset, fadeColor);

            // make sure control has time to render finished state
            if (_doneFading && !_finished)
                _finished = true;

            #if DEBUG
            Profiler.Instance.EndBlock("GUISplash.OnRender");
            #endif

            base.OnRender(offset, updateRect);
        }
コード例 #17
0
        /// <summary>
        /// Overrides the standard ml text rendering to color the text based on tags in the input
        /// string.
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="updateRect"></param>
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            DrawUtil.ClearBitmapModulation();

            RectangleF ctrlRect = new RectangleF(offset, _bounds.Extent);

            // fill the update rect with the fill color
            if (_style.IsOpaque)
                DrawUtil.RectFill(ctrlRect, _style.FillColor[CustomColor.ColorBase]);

            // if there's a border, draw the border
            if (_style.HasBorder)
                DrawUtil.Rect(ctrlRect, _style.BorderColor[CustomColor.ColorBase]);

            Vector2 pos = offset - updateRect.Point;
            Vector2 size = new Vector2(Bounds.Width, _style.Font.Instance.LineSpacing + _style.LineSpacing);
            for (int i = 0; i < _splitText.Length; i++)
            {
                int end = 0;
                CustomColor color = CustomColor.ColorUser0;
                if (_splitText[i].StartsWith("<customcolor:"))
                {
                    int start = _splitText[i].IndexOf(":") + 1;
                    end = _splitText[i].IndexOf(">");
                    color = (CustomColor)int.Parse(_splitText[i].Substring(start, end - start));
                    end++;
                }

                DrawUtil.JustifiedText(_style.Font, pos, size, _style.Alignment, _style.TextColor[color], _splitText[i].Substring(end));
                pos.Y += size.Y;
            }

            // render the child controls
            _RenderChildControls(offset, updateRect);
        }
コード例 #18
0
        /// <summary>
        /// Test to see if SceneObject can move from current position along given velocity for given amount of time
        /// without colliding with world limits.
        /// </summary>
        /// <param name="dt">Duration to move object, in seconds.</param>
        /// <param name="searchBox">Box containing entire swept path of object bounds.  Used to short cut world bounds check.</param>
        /// <param name="velocity">Velocity of object.</param>
        /// <param name="collider">Collision component of object.</param>
        /// <param name="collisions">List of collisions encountered during move.</param>
        public void TestMove(ref float dt, RectangleF searchBox, Vector2 velocity, T2DCollisionComponent collider, List<T2DCollisionInfo> collisions)
        {
            if (WorldLimitResolveCollision != null || OnWorldLimit != null)
            {
                ReadOnlyArray<T2DCollisionImage> images = SceneObject.Collision.Images;
                for (int i = 0; i < images.Count; i++)
                {
                    T2DCollisionImage image = images[i];

                    if (searchBox.X + searchBox.Width > _moveLimitMax.X)
                    {
                        // test against max x
                        _worldLimitPoly[0] = new Vector2(_moveLimitMax.X, _moveLimitMin.Y - 5.0f);
                        _worldLimitPoly[1] = new Vector2(_moveLimitMax.X, _moveLimitMax.Y + 5.0f);
                        _worldLimitImage.CollisionPolyBasis = _worldLimitPoly;
                        image.TestMove(ref dt, velocity, _worldLimitImage, collisions);
                    }
                    if (searchBox.X < _moveLimitMin.X)
                    {
                        // test against min x
                        _worldLimitPoly[0] = new Vector2(_moveLimitMin.X, _moveLimitMax.Y + 5.0f);
                        _worldLimitPoly[1] = new Vector2(_moveLimitMin.X, _moveLimitMin.Y - 5.0f);
                        _worldLimitImage.CollisionPolyBasis = _worldLimitPoly;
                        image.TestMove(ref dt, velocity, _worldLimitImage, collisions);
                    }
                    if (searchBox.Y + searchBox.Height > _moveLimitMax.Y)
                    {
                        // test against max y
                        _worldLimitPoly[0] = new Vector2(_moveLimitMax.X + 5.0f, _moveLimitMax.Y);
                        _worldLimitPoly[1] = new Vector2(_moveLimitMin.X - 5.0f, _moveLimitMax.Y);
                        _worldLimitImage.CollisionPolyBasis = _worldLimitPoly;
                        image.TestMove(ref dt, velocity, _worldLimitImage, collisions);
                    }
                    if (searchBox.Y < _moveLimitMin.Y)
                    {
                        // test against min y
                        _worldLimitPoly[0] = new Vector2(_moveLimitMin.X - 5.0f, _moveLimitMin.Y);
                        _worldLimitPoly[1] = new Vector2(_moveLimitMax.X + 5.0f, _moveLimitMin.Y);
                        _worldLimitImage.CollisionPolyBasis = _worldLimitPoly;
                        image.TestMove(ref dt, velocity, _worldLimitImage, collisions);
                    }
                }
            }
        }
コード例 #19
0
 /// <summary>
 /// Creates a rectangle from another rectangle.
 /// </summary>
 /// <param name="rectangle"></param>
 public RectangleF(RectangleF rectangle)
 {
     _point = rectangle.Point;
     _extent = rectangle.Extent;
 }
コード例 #20
0
        private void _CalculateCells()
        {
            // make sure we have two valid dimensions to work with
            if (_material as ITextureMaterial == null || _cellWidth <= 0 || _cellHeight <= 0)
                return;

            // grab the texture so we can query its dimensions
            ITextureMaterial tm = _material as ITextureMaterial;
            Resource<Texture> res = ResourceManager.Instance.LoadTexture((_material as ITextureMaterial).TextureFilename);
            Texture2D tex2d = res.Instance as Texture2D;

            // figure out the number of cells to process
            int cellCountX = tex2d.Width / _cellWidth;
            int cellCountY = tex2d.Height / _cellHeight;

            // avoid 'divide by zero' problems ahead
            if (cellCountX <= 0 || cellCountY <= 0)
                return;

            // as far as we know, we've got valid numbers
            // clear the list to repopulate
            _cellsList = new List<RectangleF>();

            // get the size per cell
            float sizePerCellX = _cellWidth / (float)tex2d.Width;
            float sizePerCellY = _cellHeight / (float)tex2d.Height;

            // declare stuff for the loop
            RectangleF cell;
            float offsetX, offsetY;

            // calculate regions and populate the cells list
            for (int y = 0; y < cellCountY; y++)
            {
                for (int x = 0; x < cellCountX; x++)
                {
                    offsetX = x * sizePerCellX;
                    offsetY = y * sizePerCellY;
                    cell = new RectangleF(offsetX, offsetY, sizePerCellX, sizePerCellY);
                    _cellsList.Add(cell);
                }
            }

            // invalidate the texture resource
            res.Invalidate();
        }
コード例 #21
0
        /// <summary>
        /// Find objects in scene container within the given search rectangle and matching the specified object types and layers.
        /// </summary>
        /// <param name="searchRect">World rectangle to search.</param>
        /// <param name="findTypes">Object types to match.</param>
        /// <param name="layerMask">Layers to match.</param>
        /// <param name="list">List which will contain results.  Note: list is not cleared.</param>
        public void FindObjects(RectangleF searchRect, TorqueObjectType findTypes, uint layerMask, List<ISceneContainerObject> list)
        {
            // prepare container system query
            _queryData.Rectangle = searchRect;
            _queryData.ObjectTypes = findTypes;
            _queryData.LayerMask = layerMask;
            _queryData.IgnoreObject = null;
            _queryData.IgnoreObjects = null;
            _queryData.FindInvisible = false;
            _queryData.IgnorePhysics = false;
            _queryData.ResultList = list;

            // do the query
            _container.FindObjects(_queryData);
        }
コード例 #22
0
        /// <summary>
        /// Called when this control is to render itself.
        /// </summary>
        /// <param name="offset">The location this control is to begin rendering.</param>
        /// <param name="updateRect">The screen area this control has drawing access to.</param>
        public virtual void OnRender(Vector2 offset, RectangleF updateRect)
        {
            ctrlRect = new RectangleF(offset, _bounds.Extent);

            // fill the update rect with the fill color
            if (_style.IsOpaque)
                DrawUtil.RectFill(ctrlRect, _style.FillColor[CustomColor.ColorBase]);

            // if there's a border, draw the border
            if (_style.HasBorder)
                DrawUtil.RectFill(ctrlRect, _style.BorderColor[CustomColor.ColorBase]);

            // render the child controls
            _RenderChildControls(offset, updateRect);
        }
コード例 #23
0
        private void _CalculateCells()
        {
            // make sure we have valid cell counts to work with
            if (_cellCountX <= 0 || _cellCountY <= 0)
                return;

            // create the new cells list
            _cellsList = new List<RectangleF>();

            // get the size per cell in local coordinates
            float sizePerCellX = 1f / _cellCountX;
            float sizePerCellY = 1f / _cellCountY;

            float offsetX = 0;
            float offsetY = 0;
            RectangleF cell;

            // calculate the different regions and populate the cells list
            for (int y = 0; y < _cellCountY; y++)
            {
                for (int x = 0; x < _cellCountX; x++)
                {
                    offsetX = x * sizePerCellX;
                    offsetY = y * sizePerCellY;
                    cell = new RectangleF(offsetX, offsetY, sizePerCellX, sizePerCellY);
                    _cellsList.Add(cell);
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// Find object in scene container within the given search radius and matching the specified object type and layers.
        /// </summary>
        /// <param name="pos">Center of search radius.</param>
        /// <param name="radius">Radius of search.</param>
        /// <param name="findTypes">Object types to match.</param>
        /// <param name="layerMask">Layers to match.</param>
        /// <param name="list">List which will contain results.  Note: list is not cleared.</param>
        public void FindObjects(Vector2 pos, float radius, TorqueObjectType findTypes, uint layerMask, List<ISceneContainerObject> list)
        {
            RectangleF searchRect = new RectangleF(pos.X - radius, pos.Y - radius, 2.0f * radius, 2.0f * radius);
            FindObjects(searchRect, findTypes, layerMask, list);

            for (int i = 0; i < list.Count; i++)
            {
                T2DSceneObject obj = list[i] as T2DSceneObject;
                if (obj == null)
                    continue;
                RectangleF objRect = obj.WorldCollisionClipRectangle;
                Vector2 objRad = 0.5f * objRect.Extent;
                Vector2 objPos = objRect.Point + objRad;

                // find closest x coord of object rect to pos
                if (pos.X < objPos.X - objRad.X)
                    objPos.X = objPos.X - objRad.X;
                else if (pos.X > objPos.X + objRad.X)
                    objPos.X = objPos.X + objRad.X;
                else
                    objPos.X = pos.X;

                // find closest y coord of object rect to pos
                if (pos.Y < objPos.Y - objRad.Y)
                    objPos.Y = objPos.Y - objRad.Y;
                else if (pos.Y > objPos.Y + objRad.Y)
                    objPos.Y = objPos.Y + objRad.Y;
                else
                    objPos.Y = pos.Y;

                // if object further than radius away, get rid of it
                if ((pos - objPos).LengthSquared() > radius * radius)
                {
                    list[i] = list[list.Count - 1];
                    list.RemoveAt(list.Count - 1);
                    i--;
                }
            }
        }
コード例 #25
0
        public override void OnRender(Vector2 offset, RectangleF updateRect)
        {
            #if DEBUG
            Profiler.Instance.StartBlock("GUIBitmap.OnRender");
            #endif

            // clear bitmap modulation
            DrawUtil.ClearBitmapModulation();

            RectangleF ctrlRect = new RectangleF(offset, _bounds.Extent);

            // fill in, if appropriate
            if (_style.IsOpaque)
                DrawUtil.RectFill(ctrlRect, _style.FillColor[CustomColor.ColorBase]);

            // set the opacity of the material
            _material.Opacity = _opacity;

            if (_material != null)
            {
                if (_material.Texture.IsNull)
                    Bitmap = _bitmapName;

                if (_style.TextureWrap)
                {
                    xDone = (_bounds.Extent.X / (_bitmapSize.X * _bitmapScale.X)) + 1;
                    yDone = (_bounds.Extent.Y / (_bitmapSize.Y * _bitmapScale.Y)) + 1;

                    xShift = (int)_wrapStart.X % (int)(_bitmapSize.X * _bitmapScale.X);
                    yShift = (int)_wrapStart.Y % (int)(_bitmapSize.Y * _bitmapScale.Y);

                    for (int y = 0; y < yDone; ++y)
                    {
                        for (int x = 0; x < xDone; ++x)
                        {
                            srcRegion.X = 0;
                            srcRegion.Y = 0;
                            srcRegion.Width = _bitmapSize.X * _bitmapScale.X;
                            srcRegion.Height = _bitmapSize.Y * _bitmapScale.Y;

                            dstRegion.X = (((_bitmapSize.X * _bitmapScale.X) * x) + offset.X) - xShift;
                            dstRegion.Y = (((_bitmapSize.Y * _bitmapScale.Y) * y) + offset.Y) - yShift;
                            dstRegion.Width = _bitmapSize.X * _bitmapScale.X;
                            dstRegion.Height = _bitmapSize.Y * _bitmapScale.Y;

                            // draw the bitmap
                            DrawUtil.BitmapStretchSR(_material, dstRegion, srcRegion, _flip);
                        }
                    }
                }
                else
                {
                    // draw the bitmap
                    if (_bitmapScale.X != 1.0f || _bitmapScale.Y != 1.0f)
                    {
                        srcRegion.X = 0;
                        srcRegion.Y = 0;
                        srcRegion.Width = _bitmapSize.X * _bitmapScale.X;
                        srcRegion.Height = _bitmapSize.Y * _bitmapScale.Y;

                        dstRegion.X = offset.X;
                        dstRegion.Y = offset.Y;
                        dstRegion.Width = Size.X * _bitmapScale.X;
                        dstRegion.Height = Size.Y * _bitmapScale.Y;

                        DrawUtil.BitmapStretchSR(_material, dstRegion, srcRegion, _flip);
                    }
                    else DrawUtil.BitmapStretch(_material, ctrlRect, _flip);
                }
            }

            // draw a border, if appropriate
            if (_style.HasBorder)
                DrawUtil.Rect(ctrlRect, _style.BorderColor[CustomColor.ColorBase]);

            #if DEBUG
            Profiler.Instance.EndBlock("GUIBitmap.OnRender");
            #endif

            // render the child controls
            _RenderChildControls(offset, updateRect);
        }
コード例 #26
0
        /// <summary>
        /// Renders controls listed under this control's hierarchy.
        /// </summary>
        /// <param name="offset">The upper-left corner of this control in screen coordinates.</param>
        /// <param name="updateRect">The intersection rectangle, in screen coordinates, of the control hierarchy.</param>
        protected void _RenderChildControls(Vector2 offset, RectangleF updateRect)
        {
            int idx;
            int numObjects = GetNumObjects();

            // store the clip
            RectangleF oldClip = DrawUtil.ClipRect;

            // offset is the upper-left corner of this control in screen coordinates
            // updateRect is the inter
            for (idx = 0; idx < numObjects; idx++)
            {
                GUIControl child = (GUIControl)GetObject(idx);
                if (child == null)
                    break;

                if (child.Visible)
                {
                    Vector2 childPosition = new Vector2(offset.X + child.Position.X, offset.Y + child.Position.Y);
                    RectangleF childClip = new RectangleF(childPosition, child.Size);

                    if (childClip.Intersect(updateRect))
                    {
                        DrawUtil.ClipRect = childClip;
                        child.OnRender(childPosition, childClip);
                    }
                }
            }

            // restore the old clip
            DrawUtil.ClipRect = oldClip;
        }
コード例 #27
0
 /// <summary>
 /// Changes the bounds of this control. A control's bounds is its position and size.
 /// </summary>
 /// <param name="newBounds">The new bounds of this control.</param>
 public void SetBounds(RectangleF newBounds)
 {
     SetBounds(newBounds.Point, newBounds.Extent);
 }
コード例 #28
0
        public void DoRectUpdate(int mipLevel, ClipStackEntry stackEntry, RectangleI srcRegion, RectangleI dstRegion)
        {
            // get a local reference to the GFXDevice's graphics device
            GraphicsDevice device = GFXDevice.Instance.Device;

            if (device.IsDisposed)
                return;

            // calculate the new destination texture coordinates
            // (custom viewports currently not fully supported on the XBox, so we use this method instead.
            // this is just as fast, so probably keep using this.)
            RectangleF dstCoords = new RectangleF(
                (float)dstRegion.X / (float)stackEntry.Texture.Width,
                (float)dstRegion.Y / (float)stackEntry.Texture.Height,
                (float)dstRegion.Width / (float)stackEntry.Texture.Width,
                (float)dstRegion.Height / (float)stackEntry.Texture.Height
                );

            // calculate the new texture coordinates
            RectangleF texCoords = new RectangleF(
                (float)srcRegion.X / ((float)stackEntry.Texture.Width * stackEntry.ScaleFactor),
                (float)srcRegion.Y / ((float)stackEntry.Texture.Height * stackEntry.ScaleFactor),
                (float)srcRegion.Width / ((float)stackEntry.Texture.Width * stackEntry.ScaleFactor),
                (float)srcRegion.Height / ((float)stackEntry.Texture.Height * stackEntry.ScaleFactor)
                );

            // custom viewports currently bugged on XBOX
            _UpdateRenderQuad(texCoords, dstCoords);

            // init the effect for this render
            _blender.SetupEffect(_toTexRenderState, null);

            // draw the quad
            while (_blender.SetupPass())
            {
                try
                {
                    device.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, _renderQuadVB, 0, 2);
                }
                catch (Exception x)
                {
                    break;
                }
            }
            // cleanup the effect after render
            _blender.CleanupEffect();
        }
コード例 #29
0
 /// Get Bin Range
 protected void _GetBins(RectangleF rectangle, out uint minBinX, out uint minBinY, out uint maxBinX, out uint maxBinY)
 {
     _GetBinRange(rectangle.X, rectangle.X + rectangle.Width, out minBinX, out maxBinX);
     _GetBinRange(rectangle.Y, rectangle.Y + rectangle.Height, out minBinY, out maxBinY);
 }
コード例 #30
0
        /// <summary>
        /// Returns whether or not this rectangle entirely contains another rectangle.
        /// </summary>
        /// <param name="rect">The rectangle to test against.</param>
        /// <returns>True if the rectangle is entirely contained.</returns>
        public bool Contains(RectangleF rect)
        {
            if (_point.X <= rect.Point.X && _point.Y <= rect.Point.Y)
            {
                if (rect.Point.X + rect.Extent.X <= _point.X + _extent.X)
                {
                    if (rect.Point.Y + rect.Extent.Y <= _point.Y + _extent.Y)
                        return true;
                }
            }

            return false;
        }