public void Render(IGraphics g, OpenGLTextureReference tex)
        {
            g.SetColor (Colors.White);

            var x = tex.X + tex.ShapeOffset.X;
            var y = tex.Y + tex.ShapeOffset.Y;

            switch (ShapeType) {
            case OpenGLShapeType.Line:
                g.DrawLine (x, y, x + A, y + B, C);
                break;
            case OpenGLShapeType.Rect:
                if (Fill) {
                    g.FillRect (x, y, A, B);
                }
                else {
                    g.DrawRect (x, y, A, B, C);
                }
                break;
            case OpenGLShapeType.RoundedRect:
                if (Fill) {
                    g.FillRoundedRect (x, y, A, B, C);
                }
                else {
                    g.DrawRoundedRect (x, y, A, B, C, D);
                }
                break;
            case OpenGLShapeType.Oval:
                if (Fill) {
                    g.FillOval (x, y, A, B);
                }
                else {
                    g.DrawOval (x, y, A, B, C);
                }
                break;
            case OpenGLShapeType.Character:
                g.SetFont (Font);
                g.DrawString (Char.ToString (), x, y);
                break;
            case OpenGLShapeType.Polygon: {
                    var dx = x - Poly.Points[0].X;
                    var dy = y - Poly.Points[0].Y;
                    var dpoly = new Polygon ();
                    for (var i = 0; i < Poly.Points.Count; i++) {
                        dpoly.AddPoint (Poly.Points[i].X + dx, Poly.Points[i].Y + dy);
                    }
                    if (Fill) {
                        g.FillPolygon (dpoly);
                    }
                    else {
                        g.DrawPolygon (dpoly, A);
                    }
                }
                break;
            case OpenGLShapeType.Arc:
                if (Fill) {
                    g.FillArc (x, y, A, B, C);
                }
                else {
                    g.DrawArc (x, y, A, B, C, D);
                }
                break;
            case OpenGLShapeType.Polyline: {
                    var dx = x - PolylinePoints[0].X;
                    var dy = y - PolylinePoints[0].Y;
                    g.BeginLines (true);
                    for (var i = 0; i < PolylineLength - 1; i++) {
                        g.DrawLine (
                            PolylinePoints[i].X + dx,
                            PolylinePoints[i].Y + dy,
                            PolylinePoints[i + 1].X + dx,
                            PolylinePoints[i + 1].Y + dy,
                            A);
                    }
                    g.EndLines ();
                }
                break;
            default:
                throw new NotSupportedException ();
            }
        }
 public bool IntersectsWith(OpenGLTextureReference other)
 {
     return Frame.IntersectsWith (other.Frame);
 }
 public void AddReference(OpenGLTextureReference texRef)
 {
     _references.Add (texRef);
 }
        public bool TryInsert(OpenGLTextureReference newRef)
        {
            //
            // Go column by column until we fit in a row
            //
            var x = Pad;
            while (x + newRef.Frame.Width + Pad < Width) {

                newRef.X = x;

                var columnFrame = new RectangleF (x, 0, newRef.Frame.Width, Height);
                var isects = GetReferencesIntersecting (columnFrame);

                var y = Pad;

                while (y + newRef.Frame.Height + Pad < Height) {

                    newRef.Y = y;

                    var intersects = false;

                    for (var i = 0; i < isects.Count && !intersects; i++) {
                        intersects = isects[i].IntersectsWith (newRef);
                        if (intersects) {
                            y = isects[i].Frame.Bottom + Pad;
                        }
                    }

                    if (!intersects) {
                        _references.Add (newRef);
                        NeedsSave = true;
                        newRef.Texture = this;
                        newRef.U = newRef.X / Width;
                        newRef.V = newRef.Y / Height;
                        newRef.TexWidth = newRef.Width / Width;
                        newRef.TexHeight = newRef.Height / Height;
                        return true;
                    }
                }

                x = isects.Average (r => r.Frame.Right) + 3;
            }

            return false;
        }
        public OpenGLShape(System.Xml.XmlReader r, List<OpenGLTexture> textures)
        {
            while (r.Read ()) {
                if (r.IsStartElement ("Info")) {
                    Info = OpenGLShapeInfo.ReadXml (r.ReadSubtree ());
                }
                else if (r.IsStartElement ("Texture")) {
                    TextureReference = new OpenGLTextureReference (r.ReadSubtree (), textures);
                }
            }

            Rendered = true;
        }