Ejemplo n.º 1
0
        public void Draw(FontLayout layout)
        {
            PrepareGroup();

            if (layout.Layout.Count == 0)
            {
                return;
            }

            var     areaSize = layout.Area.Size;
            Vector2 origin   = Vector2.Zero;

            switch (layout.Alignment)
            {
            case AlignmentType.NorthWest: break;

            case AlignmentType.SouthWest: origin.Y = areaSize.Y; break;

            case AlignmentType.West: origin.Y = areaSize.Y / 2; break;

            case AlignmentType.Center: origin = areaSize / 2; break;

            case AlignmentType.North: origin.X = areaSize.X / 2; break;

            case AlignmentType.NorthEast: origin.X = areaSize.X; break;

            case AlignmentType.East: origin.X = areaSize.X; origin.Y = areaSize.Y / 2; break;

            case AlignmentType.SouthEast: origin.X = areaSize.X; origin.Y = areaSize.Y; break;

            case AlignmentType.South: origin.X = areaSize.X / 2; origin.Y = areaSize.Y; break;
            }

            foreach (var c in layout.Layout)
            {
                var entry = new BatchEntry();
                entry.Texture       = c.Texture;
                entry.Color         = c.Color;
                entry.SourceRect    = c.Source;
                entry.Origin        = Vector2.Zero;
                entry.SpriteEffects = QuadEffects.RoundPositions;

                // TODO: Optimize
                entry.Transform =
                    Matrix.CreateTranslation(-origin.X + c.Offset.X, -origin.Y + c.Offset.Y, 0)
                    * Matrix.CreateScale(layout.Scale.X, layout.Scale.Y, 1)
                    * Matrix.CreateTranslation(origin.X + layout.Position.X, origin.Y + layout.Position.Y, 0);

                currentBatch.Entries.Add(entry);
            }
        }
Ejemplo n.º 2
0
        public QuadBatch(int defaultCapacity = 8192)
        {
            defaultEffect = new ColorTextureEffect(defaultVs, defaultFs);
            currentEffect = defaultEffect;

            capacity = defaultCapacity;
            Debug.Assert(capacity > 0);

            quads      = new Quad[capacity];
            indices    = new ushort[capacity * 6];
            fontLayout = new FontLayout();

            InitIndices();

            GL.GenBuffers(2, vertexBufferObjects);

            //GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferObjects[0]);
            //GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(capacity * 6 * Vertex2Tex2Color.GetSize()), IntPtr.Zero, BufferUsageHint.DynamicDraw);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, vertexBufferObjects[1]);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, BufferUsageHint.StaticDraw);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a copy of another layout.
 /// </summary>
 public FontLayout(FontLayout other)
     : this()
 {
     Set(other.font, other.textString, other.Area, other.color, other.alignment, other.layoutMode, other.layoutOptions);
 }