Example #1
0
        //primitives
        public virtual void begin(IRenderTarget target, GLSortMode mode)
        {
            if (_begin)
            {
                throw new InvalidOperationException("You must call end before you can call begin again.");
            }

            if (_stateStack.Count > 0)
            {
                throw new InvalidOperationException("State stack was not empty.");
            }

            if (_clipStack.Count > 0)
            {
                throw new InvalidOperationException("Clipping stack was not empty.");
            }

            if (_effectStack.Count > 0)
            {
                throw new InvalidOperationException("Effect stack was not empty.");
            }

            _target          = target;
            _begin           = true;
            _sortMode        = mode;
            _renderableIndex = 0;
            _clipping        = AxisAlignedBox2.Null;
            _effect          = null;
            //_currentMatrix = Matrix3.Identity;
            _state = GLState.empty;

            _target.enable();
            //check other settings
        }
Example #2
0
        internal void DrawText(GL gl, string text, float?width)
        {
            var dx = 0f;// Utility.Floor(pos.X);

            //var dy = Utility.Floor(pos.Y);
            foreach (char c in text)
            {
                FontChar fc;
                if (_characterMap.TryGetValue(c, out fc))
                {
                    if (width.HasValue && dx + fc.XAdvance > width.Value)
                    {
                        break;
                    }

                    var sourceRectangle = AxisAlignedBox2.FromRect(fc.X, fc.Y, fc.Width, fc.Height);
                    var destRectangle   = AxisAlignedBox2.FromRect(fc.XOffset, fc.YOffset, fc.Width, fc.Height);

                    gl.source(sourceRectangle);
                    gl.quad(destRectangle);
                    gl.translate(new Vector2(fc.XAdvance, 0));

                    dx += fc.XAdvance;
                }
            }
        }
Example #3
0
        internal void DrawWrappedOnWordText(GL gl, string text, Vector2 size)
        {
            var currentSize = Vector2.Zero;
            var current     = 0;

            while (current != -1 && current < text.Length)
            {
                var start = current;
                current = FindWordIndexFromBounds(current, size.X, text, out currentSize);

                if (current > 0)
                {
                    var p = gl.currentPosition;
                    for (int i = start; i < current; i++)
                    {
                        var      c = text[i];
                        FontChar fc;
                        if (_characterMap.TryGetValue(c, out fc))
                        {
                            var sourceRectangle = AxisAlignedBox2.FromRect(fc.X, fc.Y, fc.Width, fc.Height);
                            var destRectangle   = AxisAlignedBox2.FromRect(fc.XOffset, fc.YOffset, fc.Width, fc.Height);
                            gl.source(sourceRectangle);
                            gl.quad(destRectangle);
                            gl.translate(new Vector2(fc.XAdvance, 0));

                            //dx += fc.XAdvance;
                        }
                    }
                    gl.position(p);
                    gl.translate(new Vector2(0, MaxLineHeight));
                }

                size.Y += currentSize.Y;
            }
        }
        public object Deserialize(JsonValue _jv)
        {
            if (_jv.Type == JsonTypes.Null)
            {
                return(null);
            }

            var ja   = (JsonArray)_jv;
            var data = new AxisAlignedBox2[ja.Count];

            for (var i = 0; i < data.Length; i++)
            {
                var jv = ja[i];
                if (jv.Type == JsonTypes.Object)
                {
                    var jo  = (JsonObject)jv;
                    var min = jo["min"];
                    var max = jo["max"];

                    if (min.Type == JsonTypes.Object && max.Type == JsonTypes.Object)
                    {
                        var jmin = (JsonObject)min;
                        var jmax = (JsonObject)max;

                        var vmin = new Vector2();
                        var vmax = new Vector2();

                        var jminx = jmin["x"];
                        var jminy = jmin["y"];
                        if (jminx.Type == JsonTypes.Number)
                        {
                            vmin.X = (float)jminx;
                        }

                        if (jminy.Type == JsonTypes.Number)
                        {
                            vmin.Y = (float)jminy;
                        }

                        var jmaxx = jmax["x"];
                        var jmaxy = jmax["y"];
                        if (jmaxx.Type == JsonTypes.Number)
                        {
                            vmax.X = (float)jmaxx;
                        }

                        if (jmaxy.Type == JsonTypes.Number)
                        {
                            vmax.Y = (float)jmaxy;
                        }

                        data[i].SetExtents(vmin, vmax);
                    }
                }
            }
            return(data);
        }
Example #5
0
        public virtual void endclip()
        {
            verifyBegin();

            if (_clipStack.Count == 0)
            {
                throw new InvalidOperationException("Clipping stack was already empty.");
            }

            _clipping = _clipStack.Pop();
        }
Example #6
0
        public void line(Vector2 start, Vector2 end, Real width, Real rotation)
        {
            if (rotation != 0)
            {
                start = start.Rotate(Vector2.Zero, rotation);
                end   = end.Rotate(Vector2.Zero, rotation);
            }

            var diff = end - start;
            //var srcRect = new AxisAlignedBox(start.X, start.Y - width * 0.5f, start.X + diff.Length(), start.Y + width * 0.5f);

            var srcRect = new AxisAlignedBox2(start.X, start.Y, start.X + width, start.Y + diff.Length);

            diff.Normalize();

            var _rotation = Utility.ATan2(diff.Y, diff.X) - Utility.PIOverTwo;
            //Draw(renderQueue, material, srcRect, AxisAlignedBox2.Null, color, rotation, new Vector2(0.5f, 0), SpriteEffects.None, depth);

            var item = new GLRenderable();

            item.color           = _state.color;
            item.depth           = _state.depth;
            item.material        = _state.material;
            item.pivot           = new Vector2(0.5f, 0);
            item.position        = (_state.position + start) * _state.scale;
            item.rotation        = _rotation;
            item.scale           = srcRect.Size * _state.scale;
            item.scissorRect     = _clipping;
            item.applyScissor    = !_clipping.IsNull;
            item.sourceRectangle = _state.source;
            item.effect          = _effect;
            item.type            = GLRenderableType.Line;
            item.key             = 0;

            draw(item);
        }
Example #7
0
 /// <summary>
 ///		Returns whether or not this Circle interects a box.
 /// </summary>
 /// <param name="box"></param>
 /// <returns>True if the box intersects, false otherwise.</returns>
 public bool Intersects(AxisAlignedBox2 box)
 {
     return(Utility.Intersects(this, box));
 }
 public static XnaMath.Rectangle ToRect(this AxisAlignedBox2 aabb)
 {
     return(new XnaMath.Rectangle(
                (int)System.Math.Floor(aabb.X0), (int)System.Math.Floor(aabb.Y0),
                (int)System.Math.Ceiling(aabb.Width), (int)System.Math.Ceiling(aabb.Height)));
 }
Example #9
0
 public virtual void beginclip(AxisAlignedBox2 clipregion)
 {
     verifyBegin();
     _clipStack.Push(_clipping);
     _clipping = clipregion;
 }
Example #10
0
        private bool checkScissorRect(AxisAlignedBox2 aabb)
        {
            var scissor = aabb.ToRect();

            return(scissor == batch.GraphicsDevice.ScissorRectangle);
        }
Example #11
0
 //public void rect(Vector2 size, Real width) { rect(Vector2.Zero, size, width, _state.rotation); }
 public void rect(AxisAlignedBox2 a, Real width)
 {
     rect(a.minVector, a.maxVector, width, _state.rotation);
 }
Example #12
0
 //public void rect(Vector2 size) { rect(Vector2.Zero, size, 1f, _state.rotation); }
 public void rect(AxisAlignedBox2 a)
 {
     rect(a.minVector, a.maxVector, 1f, _state.rotation);
 }
Example #13
0
 public void quad(AxisAlignedBox2 a, Vector2 pivot, Real rotation)
 {
     quad(a.minVector, a.maxVector, pivot, rotation);
 }
Example #14
0
 public void quad(AxisAlignedBox2 a, Real rotation)
 {
     quad(a.minVector, a.maxVector, new Vector2(0.5f, 0.5f), rotation);
 }
Example #15
0
 public void quad(AxisAlignedBox2 a)
 {
     quad(a.minVector, a.maxVector, new Vector2(0.5f, 0.5f), _state.rotation);
 }
Example #16
0
 /// <summary>
 ///    Tests whether this ray intersects the given box.
 /// </summary>
 /// <param name="box"></param>
 /// <returns>
 ///		Struct containing info on whether there was a hit, and the distance from the
 ///		origin of this ray where the intersect happened.
 ///	</returns>
 public IntersectResult Intersects(AxisAlignedBox2 box)
 {
     return(Utility.Intersects(this, box));
 }
Example #17
0
 public virtual void source(AxisAlignedBox2 src)
 {
     verifyBegin();
     _state.source = src;
 }