Exemplo n.º 1
0
        public ResizeHandles(Layer layer)
        {
            for (int i = 0; i < mHandles.Length; i++)
            {
                mHandles[i] = new LineCircle();
                mHandles[i].Radius = RadiusAtNoZoom;
                ShapeManager.Self.Add(mHandles[i], layer);

            }

            mXLine1 = new Line(null);
            mXLine2 = new Line(null);
            mXLine1.Name = "Resize Handle X Line 1";
            mXLine2.Name = "Resize Handle X Line 2";

            ShapeManager.Self.Add(mXLine1, layer);
            ShapeManager.Self.Add(mXLine2, layer);

            mOriginLine = new Line(null);
            mOriginLine.Name = "Resize Handle Offset Line";
            ShapeManager.Self.Add(mOriginLine, layer);

            Visible = true;
            UpdateToProperties();
        }
Exemplo n.º 2
0
        public void Add(SolidRectangle solidRectangle, Layer layer = null)
        {
            if (layer == null)
            {
                layer = Renderer.LayersWritable[0];
            }

            mSolidRectangles.Add(solidRectangle);
            layer.Add(solidRectangle);
        }
Exemplo n.º 3
0
        public void Add(Text text, Layer layer)
        {
            if (layer == null)
            {
                layer = Renderer.LayersWritable[0];
            }
            mTexts.Add(text);
#if !TEST
            layer.Add(text);
#endif
        }
Exemplo n.º 4
0
        public void Add(LineRectangle lineRectangle, Layer layer)
        {
            if (layer == null)
            {
                layer = Renderer.LayersWritable[0];
            }

            mRectangles.Add(lineRectangle);

            layer.Add(lineRectangle);
        }
Exemplo n.º 5
0
        public void Add(Sprite sprite, Layer layer = null)
        {
            mSprites.Add(sprite);
#if !TEST

            if (layer == null)
            {
                layer = Renderer.LayersWritable[0];
            }

            layer.Add(sprite);
#endif
        }
Exemplo n.º 6
0
        public void BeginSpriteBatch(RenderStateVariables renderStates, Layer layer, BeginType beginType, Camera camera)
        {

            Matrix matrix = GetZoomAndMatrix(layer, camera);

            SamplerState samplerState = GetSamplerState(renderStates);


            bool isFullscreen = renderStates.ClipRectangle == null;

            RasterizerState rasterizerState;
            if (isFullscreen)
            {
                rasterizerState = scissorTestDisabled;
            }
            else
            {
                rasterizerState = scissorTestEnabled;
            }


            Rectangle scissorRectangle = new Rectangle();
            if (rasterizerState.ScissorTestEnable)
            {
                scissorRectangle = renderStates.ClipRectangle.Value;
            }


            DepthStencilState depthStencilState = DepthStencilState.DepthRead;

            if (beginType == BeginType.Begin)
            {
                mSpriteBatch.ReplaceRenderStates(SpriteSortMode.Immediate, renderStates.BlendState,
                    samplerState,
                    depthStencilState,
                    rasterizerState,
                    null, matrix,
                    scissorRectangle);
            }
            else
            {
                mSpriteBatch.PushRenderStates(SpriteSortMode.Immediate, renderStates.BlendState,
                    samplerState,
                    depthStencilState,
                    rasterizerState,
                    null, matrix,
                    scissorRectangle);
            }
        }
Exemplo n.º 7
0
 private void CreateLayer()
 {
     mLayer = Renderer.AddLayer();
     mLayer.LayerCameraSettings = new LayerCameraSettings();
     mLayer.LayerCameraSettings.IsInScreenSpace = true;
     mLayer.Name = "Ruler Layer";
 }
Exemplo n.º 8
0
 public void Draw(Layer layer)
 {
     Renderer.Draw(this, layer);
 }
Exemplo n.º 9
0
        private RasterizerState GetRasterizerState(RenderStateVariables renderStates, Layer layer)
        {
            bool isFullscreen = layer.ScissorIpso == null;

            if (isFullscreen)
            {
                return scissorTestDisabled;
            }
            else
            {
                return scissorTestEnabled;
            }
        }
Exemplo n.º 10
0
        private void BeginSpriteBatch(RenderStateVariables renderStates, Layer layer, BeginType beginType)
        {
            Matrix matrix = GetZoomAndMatrix(layer);

            SamplerState samplerState = GetSamplerState(renderStates);

            RasterizerState rasterizerState = GetRasterizerState(renderStates, layer);

            Rectangle scissorRectangle = new Rectangle();
            if(rasterizerState.ScissorTestEnable)
            {
                scissorRectangle = layer.GetScissorRectangleFor(mCamera);
            }

            DepthStencilState depthStencilState = DepthStencilState.DepthRead;

            if (beginType == BeginType.Begin)
            {
                mSpriteBatch.Begin(SpriteSortMode.Immediate, renderStates.BlendState,
                    samplerState,
                    depthStencilState,
                    rasterizerState,
                    null, matrix,
                    scissorRectangle);
            }
            else
            {
                mSpriteBatch.Push(SpriteSortMode.Immediate, renderStates.BlendState,
                    samplerState,
                    depthStencilState,
                    rasterizerState,
                    null, matrix,
                    scissorRectangle);
            }
            mDrawCallsPerFrame++;
        }
Exemplo n.º 11
0
        private void Render(IEnumerable<IRenderableIpso> whatToRender, SystemManagers managers, Layer layer)
        {
            foreach(var renderable in whatToRender)
            {
                var oldClip = mRenderStateVariables.ClipRectangle;
                AdjustRenderStates(mRenderStateVariables, layer, renderable);
                bool didClipChange = oldClip != mRenderStateVariables.ClipRectangle;

                renderable.Render(spriteRenderer, managers);


                if (RenderUsingHierarchy)
                {
                    Render(renderable.Children, managers, layer);
                }

                if(didClipChange)
                {
                    mRenderStateVariables.ClipRectangle = oldClip;
                    spriteRenderer.BeginSpriteBatch(mRenderStateVariables, layer, BeginType.Begin, mCamera);
                }
            }
        }
Exemplo n.º 12
0
        private void AddChildren(SystemManagers managers, Layer layer)
        {
            // In a simple situation we'd just loop through the
            // ContainedElements and add them to the manager.  However,
            // this means that the container will dictate the Layer that
            // its children reside on.  This is not what we want if we have
            // two children, one of which is attached to the other, and the parent
            // instance clips its children.  Therefore, we should make sure that we're
            // only adding direct children and letting instances handle their own children

            if (this.ElementSave != null && this.ElementSave is ScreenSave)
            {

                //Recursively add children to the managers
                foreach (var child in this.mWhatThisContains)
                {
                    // July 27, 2014
                    // Is this an unnecessary check?
                    // if (child is GraphicalUiElement)
                    {
                        // December 1, 2014
                        // I think that when we
                        // add a screen we should
                        // add all of the children of
                        // the screen.  There's nothing
                        // "above" that.
                        if (child.Parent == null || child.Parent == this)
                        {
                            (child as GraphicalUiElement).AddToManagers(managers, layer);
                        }
                        else
                        {
                            child.mManagers = this.mManagers;

                            child.CustomAddToManagers();

                            child.CustomAddChildren();
                        }
                    }
                }
            }
            else if (this.Children != null)
            {
                foreach (var child in this.Children)
                {
                    if (child is GraphicalUiElement)
                    {
                        var childGue = child as GraphicalUiElement;

                        if (child.Parent == null || child.Parent == this)
                        {
                            childGue.AddToManagers(managers, layer);
                        }
                        else
                        {
                            childGue.mManagers = this.mManagers;

                            childGue.CustomAddToManagers();

                            childGue.CustomAddChildren();
                        }
                    }
                }

                // If a Component contains a child and that child is parented to the screen bounds then we should still add it
                foreach (var child in this.mWhatThisContains)
                {
                    var childGue = child as GraphicalUiElement;

                    // We'll check if this child has a parent, and if that parent isn't part of this component. If not, then
                    // we'll add it
                    if (child.Parent != null && this.mWhatThisContains.Contains(child.Parent) == false)
                    {
                        childGue.AddToManagers(managers, layer);
                    }
                    else
                    {
                        childGue.mManagers = this.mManagers;

                        childGue.CustomAddToManagers();

                        childGue.CustomAddChildren();
                    }
                }
            }
        }
Exemplo n.º 13
0
        public void Add(NineSlice nineSlice, Layer layer = null)
        {
            mNineSlices.Add(nineSlice);

#if !TEST
            if (layer == null)
            {
                layer = Renderer.LayersWritable[0];
            }
            layer.Add(nineSlice);
#endif
        }
Exemplo n.º 14
0
 public Layer AddLayer()
 {
     Layer layer = new Layer();
     mLayers.Add(layer);
     return layer;
 }
Exemplo n.º 15
0
        public void AddLayer(SortableLayer sortableLayer, Layer masterLayer)
        {
            if (masterLayer == null)
            {
                masterLayer = LayersWritable[0];
            }

            masterLayer.Add(sortableLayer);
        }
Exemplo n.º 16
0
 private void CreateLayer()
 {
     mLayer = mManagers.Renderer.AddLayer();
     mLayer.LayerCameraSettings = new LayerCameraSettings();
     mLayer.LayerCameraSettings.IsInScreenSpace = true;
 }
Exemplo n.º 17
0
        public void MoveToLayer(Layer layer)
        {
            var layerToRemoveFrom = mLayer;
            if (mLayer == null && mManagers != null)
            {
                layerToRemoveFrom = mManagers.Renderer.Layers[0];
            }

            var layerToAddTo = layer;
            if (layerToAddTo == null)
            {
                layerToAddTo = mManagers.Renderer.Layers[0];
            }

            //if (mSortableLayer != null)
            //{
            //    // all renderables are part of the mSortableLayer, so we
            //    // just move the mSortableLayer and everything comes along with it:
            //    mManagers.Renderer.RemoveLayer(mSortableLayer);
            //    mManagers.Renderer.AddLayer(mSortableLayer, layer);
            //}
            //else
            {
                // This may be a Screen
                if (mContainedObjectAsIpso != null)
                {
                    if(layerToRemoveFrom != null)
                    {
                        layerToRemoveFrom.Remove(mContainedObjectAsIpso);
                    }
                    layerToAddTo.Add(mContainedObjectAsIpso);
                }

                // We don't want to move the children to a layer, because the children
                // are drawn hierarchically
                //foreach (var contained in this.mWhatThisContains)
                //{
                //    contained.MoveToLayer(layer);
                //}
            }
        }
Exemplo n.º 18
0
        private void AddContainedRenderableToManagers(SystemManagers managers, Layer layer)
        {
            // This may be a Screen
            if (mContainedObjectAsIpso != null)
            {

                if (mContainedObjectAsIpso is Sprite)
                {
                    managers.SpriteManager.Add(mContainedObjectAsIpso as Sprite, layer);
                }
                else if (mContainedObjectAsIpso is NineSlice)
                {
                    managers.SpriteManager.Add(mContainedObjectAsIpso as NineSlice, layer);
                }
                else if (mContainedObjectAsIpso is LineRectangle)
                {
                    managers.ShapeManager.Add(mContainedObjectAsIpso as LineRectangle, layer);
                }
                else if (mContainedObjectAsIpso is SolidRectangle)
                {
                    managers.ShapeManager.Add(mContainedObjectAsIpso as SolidRectangle, layer);
                }
                else if (mContainedObjectAsIpso is Text)
                {
                    managers.TextManager.Add(mContainedObjectAsIpso as Text, layer);
                }
                else if (mContainedObjectAsIpso is LineCircle)
                {
                    managers.ShapeManager.Add(mContainedObjectAsIpso as LineCircle, layer);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Exemplo n.º 19
0
 public GraphicalOutline(Layer uiLayer)
 {
     SelectionBorder = 0;
     mUiLayer = uiLayer;
 }
Exemplo n.º 20
0
        public void Add(LineCircle lineCircle, Layer layer)
        {
            mCircles.Add(lineCircle);

            if (layer == null)
            {
                layer = Renderer.LayersWritable[0];
            }

            layer.Add(lineCircle);
        }
Exemplo n.º 21
0
        private Matrix GetZoomAndMatrix(Layer layer, Camera camera)
        {
            Matrix matrix;

            if (layer.LayerCameraSettings != null)
            {
                if (layer.LayerCameraSettings.IsInScreenSpace)
                {
                    float zoom = 1;
                    if (layer.LayerCameraSettings.Zoom.HasValue)
                    {
                        zoom = layer.LayerCameraSettings.Zoom.Value;
                    }
                    matrix = Matrix.CreateScale(zoom);
                    CurrentZoom = zoom;
                }
                else
                {
                    float zoom = camera.Zoom;
                    if (layer.LayerCameraSettings.Zoom.HasValue)
                    {
                        zoom = layer.LayerCameraSettings.Zoom.Value;
                    }
                    matrix = Camera.GetTransformationMatirx(camera.X, camera.Y, zoom, camera.ClientWidth, camera.ClientHeight);
                    CurrentZoom = zoom;
                }
            }
            else
            {
                matrix = camera.GetTransformationMatrix();
                CurrentZoom = camera.Zoom;
            }
            return matrix;
        }
Exemplo n.º 22
0
        private void AdjustRenderStates(RenderStateVariables renderState, Layer layer, IRenderableIpso renderable)
        {
            BlendState renderBlendState = renderable.BlendState;
            bool wrap = renderable.Wrap;
            bool shouldResetStates = false;

            if (renderBlendState == null)
            {
                renderBlendState = BlendState.NonPremultiplied;
            }
            if (renderState.BlendState != renderBlendState)
            {
                renderState.BlendState = renderable.BlendState;
                shouldResetStates = true;

            }

            if (renderState.Wrap != wrap)
            {
                renderState.Wrap = wrap;
                shouldResetStates = true;
            }

            if (renderable.ClipsChildren)
            {
                Rectangle clipRectangle = GetScissorRectangleFor(Camera, renderable);

                if (renderState.ClipRectangle == null || clipRectangle != renderState.ClipRectangle.Value)
                {
                    //todo: Don't just overwrite it, constrain this rect to the existing one, if it's not null: 

                    var adjustedRectangle = clipRectangle;
                    if (renderState.ClipRectangle != null)
                    {
                        adjustedRectangle = ConstrainRectangle(clipRectangle, renderState.ClipRectangle.Value);
                    }


                    renderState.ClipRectangle = adjustedRectangle;
                    shouldResetStates = true;
                }

            }


            if (shouldResetStates)
            {
                spriteRenderer.BeginSpriteBatch(renderState, layer, BeginType.Begin, mCamera);
            }
        }
Exemplo n.º 23
0
        public void Draw(SystemManagers managers, Layer layer)
        {
            // So that 2 controls don't render at the same time.
            lock (LockObject)
            {
                mCamera.UpdateClient();

                var oldSampler = GraphicsDevice.SamplerStates[0];

                mRenderStateVariables.BlendState = BlendState.NonPremultiplied;
                mRenderStateVariables.Wrap = false;

                RenderLayer(managers, layer);

                if (oldSampler != null)
                {
                    GraphicsDevice.SamplerStates[0] = oldSampler;
                }
            }
        }
Exemplo n.º 24
0
        public virtual void AddToManagers(SystemManagers managers, Layer layer)
        {
#if DEBUG
            if (managers == null)
            {
                throw new ArgumentNullException("managers cannot be null");
            }
#endif
            // If mManagers isn't null, it's already been added
            if (mManagers == null)
            {
                mLayer = layer;
                mManagers = managers;

                AddContainedRenderableToManagers(managers, layer);

                // Custom should be called before children have their Custom called
                CustomAddToManagers();

                // that means this is a screen, so the children need to be added directly to managers
                if (this.mContainedObjectAsIpso == null)
                {
                    AddChildren(managers, layer);
                }
                else
                {
                    CustomAddChildren();
                }
            }
        }
Exemplo n.º 25
0
        public void Add(Line line, Layer layer = null)
        {
            if(layer == null)
            {
                layer = Renderer.LayersWritable[0];
            }

            mLines.Add(line);
            layer.Add(line);
        }
Exemplo n.º 26
0
 public void RemoveLayer(Layer layer)
 {
     mLayers.Remove(layer);
 }
Exemplo n.º 27
0
        internal void RenderLayer(SystemManagers managers, Layer layer)
        {
            // If the Layer's clip region has no width or height, then let's
            // skip over rendering it, otherwise XNA crashes:
            var clipRegion = layer.GetScissorRectangleFor(managers.Renderer.Camera);

            if(clipRegion.Width != 0 && clipRegion.Height != 0)
            {
                BeginSpriteBatch(mRenderStateVariables, layer, BeginType.Push);

                layer.SortRenderables();

                foreach (IRenderable renderable in layer.RenderablesWriteable)
                {
                    AdjustRenderStates(mRenderStateVariables, layer, renderable);
                    renderable.Render(mSpriteBatch.SpriteBatch, managers);
                }

                mSpriteBatch.Pop();
            }
        }
Exemplo n.º 28
0
        private void AdjustRenderStates(RenderStateVariables renderState, Layer layer, IRenderable renderable)
        {
            BlendState renderBlendState = renderable.BlendState;
            bool wrap = renderable.Wrap;
            bool shouldResetStates = false;

            if (renderBlendState == null)
            {
                renderBlendState = BlendState.NonPremultiplied;
            }
            if (renderState.BlendState != renderBlendState)
            {
                renderState.BlendState = renderable.BlendState;
                shouldResetStates = true;

            }

            if (renderState.Wrap != wrap)
            {
                renderState.Wrap = wrap;
                shouldResetStates = true;
            }

            if (shouldResetStates)
            {
                BeginSpriteBatch(renderState, layer, BeginType.Begin);
            }
        }
Exemplo n.º 29
0
        public void Add(LineGrid lineGrid, Layer layer = null)
        {
            if (layer == null)
            {
                layer = Renderer.LayersWritable[0];
            }

            mGrids.Add(lineGrid);
            layer.Add(lineGrid);
        }
Exemplo n.º 30
0
        internal void RenderLayer(SystemManagers managers, Layer layer, bool prerender = true)
        {
            //////////////////Early Out////////////////////////////////
            if (layer.Renderables.Count == 0)
            {
                return;
            }
            ///////////////End Early Out///////////////////////////////

            if (prerender)
            {
                PreRender(layer.Renderables);
            }

            spriteRenderer.BeginSpriteBatch(mRenderStateVariables, layer, BeginType.Push, mCamera);

            layer.SortRenderables();

            Render(layer.Renderables, managers, layer);

            spriteRenderer.EndSpriteBatch();
        }