示例#1
0
        public void FillConvexPath(GLConvexPath geo, GLBrush brush, bool smooth = false)
        {
            if (!brush.IsGradient)
            {
                if (smooth)
                    GL.Enable(EnableCap.PolygonSmooth);
                GL.Color4(brush.Color0);
                GL.Begin(BeginMode.TriangleFan);
                foreach (var pt in geo.Points)
                    GL.Vertex2(pt.X, pt.Y);
                GL.End();
                if (smooth)
                    GL.Disable(EnableCap.PolygonSmooth);
            }
            else
            {
                Debug.Assert(brush.GradientSizeX == 0.0f);

                GL.Begin(BeginMode.TriangleFan);
                foreach (var pt in geo.Points)
                {
                    float lerp = pt.Y / (float)brush.GradientSizeY;
                    byte r = (byte)(brush.Color0.R * (1.0f - lerp) + (brush.Color1.R * lerp));
                    byte g = (byte)(brush.Color0.G * (1.0f - lerp) + (brush.Color1.G * lerp));
                    byte b = (byte)(brush.Color0.B * (1.0f - lerp) + (brush.Color1.B * lerp));
                    byte a = (byte)(brush.Color0.A * (1.0f - lerp) + (brush.Color1.A * lerp));

                    GL.Color4(r, g, b, a);
                    GL.Vertex2(pt.X, pt.Y);
                }
                GL.End();
            }
        }
示例#2
0
        public void DrawRectangle(float x0, float y0, float x1, float y1, GLBrush brush, float width = 1.0f)
        {
            GL.PushMatrix();
            GL.Translate(0.5f, 0.5f, 0);
            GL.Color4(brush.Color0);
#if FAMISTUDIO_LINUX
            if (!supportsLineWidth && width > 1)
            {
                DrawThickLineAsPolygon(new[] { 
                    x0, y0, 
                    x1, y0, 
                    x1, y1, 
                    x0, y1,
                    x0, y0 }, brush, width);
            }
            else
#endif
            {
                GL.LineWidth(width);
                GL.Begin(BeginMode.LineLoop);
                GL.Vertex2(x0, y0);
                GL.Vertex2(x1, y0);
                GL.Vertex2(x1, y1);
                GL.Vertex2(x0, y1);
                GL.End();
            }
            GL.PopMatrix();
        }
示例#3
0
        public void FillConvexPath(GLConvexPath geo, GLBrush brush)
        {
            if (!brush.IsGradient)
            {
                GL.Color4(brush.Color0);
                GL.Begin(BeginMode.TriangleFan);
                foreach (var pt in geo.Points)
                {
                    GL.Vertex2(pt.X + 0.5f, pt.Y + 0.5f);
                }
                GL.End();
            }
            else
            {
                Debug.Assert(brush.GradientSizeX == 0.0f);

                GL.Begin(BeginMode.TriangleFan);
                foreach (var pt in geo.Points)
                {
                    float lerp = pt.Y / (float)brush.GradientSizeY;
                    byte  r    = (byte)(brush.Color0.R * (1.0f - lerp) + (brush.Color1.R * lerp));
                    byte  g    = (byte)(brush.Color0.G * (1.0f - lerp) + (brush.Color1.G * lerp));
                    byte  b    = (byte)(brush.Color0.B * (1.0f - lerp) + (brush.Color1.B * lerp));
                    byte  a    = (byte)(brush.Color0.A * (1.0f - lerp) + (brush.Color1.A * lerp));

                    GL.Color4(r, g, b, a);
                    GL.Vertex2(pt.X + 0.5f, pt.Y + 0.5f);
                }
                GL.End();
            }
        }
示例#4
0
 public void DrawLine(float[,] points, GLBrush brush)
 {
     for (int i = 0; i < points.GetLength(0) - 1; i++)
     {
         DrawLine(points[i + 0, 0], points[i + 0, 1], points[i + 1, 0], points[i + 1, 1], brush);
     }
 }
示例#5
0
        public void DrawConvexPath(GLConvexPath geo, GLBrush brush, float lineWidth = 1.0f)
        {
            GL.PushMatrix();
            GL.Translate(0.5f, 0.5f, 0);
            GL.Enable(EnableCap.LineSmooth);
            GL.Color4(brush.Color0);
#if FAMISTUDIO_LINUX
            if (!supportsLineWidth && lineWidth > 1)
            {
                var pts = new float[geo.Points.Length * 2 + 2];
                for (int i = 0; i < geo.Points.Length; i++)
                {
                    pts[i * 2 + 0] = geo.Points[i].X;
                    pts[i * 2 + 1] = geo.Points[i].Y;
                }
                pts[geo.Points.Length * 2 + 0] = geo.Points[0].X;
                pts[geo.Points.Length * 2 + 1] = geo.Points[0].Y;

                DrawThickLineAsPolygon(pts, brush, lineWidth);
            }
            else
#endif
            {
                GL.LineWidth(lineWidth);
                GL.Begin(BeginMode.LineLoop);
                foreach (var pt in geo.Points)
                {
                    GL.Vertex2(pt.X, pt.Y);
                }
                GL.End();
            }
            GL.Disable(EnableCap.LineSmooth);
            GL.PopMatrix();
        }
示例#6
0
        public void DrawText(string text, GLFont font, float startX, float startY, GLBrush brush, float width = 1000)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, font.Texture);
            GL.Color4(brush.Color0.R, brush.Color0.G, brush.Color0.B, (byte)255);
            GL.Begin(BeginMode.Quads);

            int alignmentOffsetX = 0;

            if (font.Alignment != 0)
            {
                font.MeasureString(text, out int minX, out int maxX);

                if (font.Alignment == 1)
                {
                    alignmentOffsetX -= minX;
                    alignmentOffsetX += ((int)width - maxX - minX) / 2;
                }
                else
                {
                    alignmentOffsetX -= minX;
                    alignmentOffsetX += ((int)width - maxX - minX);
                }
            }

            int x = (int)(startX + alignmentOffsetX);
            int y = (int)(startY + font.OffsetY);

            for (int i = 0; i < text.Length; i++)
            {
                var c0   = text[i];
                var info = font.GetCharInfo(c0);

                int x0 = x + info.xoffset;
                int y0 = y + info.yoffset;
                int x1 = x0 + info.width;
                int y1 = y0 + info.height;

                GL.TexCoord2(info.u0, info.v0); GL.Vertex2(x0, y0);
                GL.TexCoord2(info.u1, info.v0); GL.Vertex2(x1, y0);
                GL.TexCoord2(info.u1, info.v1); GL.Vertex2(x1, y1);
                GL.TexCoord2(info.u0, info.v1); GL.Vertex2(x0, y1);

                x += info.xadvance;
                if (i != text.Length - 1)
                {
                    char c1 = text[i + 1];
                    x += font.GetKerning(c0, c1);
                }
            }

            GL.End();
            GL.Disable(EnableCap.Texture2D);
        }
示例#7
0
 public void DrawLine(float x0, float y0, float x1, float y1, GLBrush brush, float width = 1.0f)
 {
     GL.Color4(brush.Color0);
     GL.LineWidth(width);
     GL.Begin(BeginMode.Lines);
     GL.Vertex2(x0 + 0.5f, y0 + 0.5f);
     GL.Vertex2(x1 + 0.5f, y1 + 0.5f);
     GL.End();
 }
示例#8
0
 public void DrawRectangle(float x0, float y0, float x1, float y1, GLBrush brush)
 {
     GL.Color4(brush.Color0);
     GL.Begin(BeginMode.LineLoop);
     GL.Vertex2(x0 + 0.5f, y0 + 0.5f);
     GL.Vertex2(x1 + 0.5f, y0 + 0.5f);
     GL.Vertex2(x1 + 0.5f, y1 + 0.5f);
     GL.Vertex2(x0 + 0.5f, y1 + 0.5f);
     GL.End();
 }
示例#9
0
 public void DrawConvexPath(GLConvexPath geo, GLBrush brush)
 {
     GL.Enable(EnableCap.LineSmooth);
     GL.Color4(brush.Color0);
     GL.Begin(BeginMode.LineLoop);
     foreach (var pt in geo.Points)
     {
         GL.Vertex2(pt.X + 0.5f, pt.Y + 0.5f);
     }
     GL.End();
     GL.Disable(EnableCap.LineSmooth);
 }
示例#10
0
        public void DrawRectangle(float x0, float y0, float x1, float y1, GLBrush brush, float width = 1.0f)
        {
            GL.PushMatrix();
            GL.Translate(0.5f, 0.5f, 0);
            GL.Color4(brush.Color0);
#if FAMISTUDIO_LINUX
            if (!supportsLineWidth && width > 1)
            {
                DrawThickLineAsPolygon(new[] {
                    x0, y0,
                    x1, y0,
                    x1, y1,
                    x0, y1,
                    x0, y0
                }, brush, width);
            }
            else
#endif
            {
                if (brush.IsBitmap)
                {
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, brush.Bitmap.Id);
                    GL.LineWidth(width);
                    GL.Begin(BeginMode.LineLoop);

                    var size = brush.Bitmap.Size;
                    GL.TexCoord2((x0 + 0.5f) / size.Width, (y0 + 0.5f) / size.Height);
                    GL.Vertex2(x0, y0);
                    GL.TexCoord2((x1 + 0.5f) / size.Width, (y0 + 0.5f) / size.Height);
                    GL.Vertex2(x1, y0);
                    GL.TexCoord2((x1 + 0.5f) / size.Width, (y1 + 0.5f) / size.Height);
                    GL.Vertex2(x1, y1);
                    GL.TexCoord2((x0 + 0.5f) / size.Width, (y1 + 0.5f) / size.Height);
                    GL.Vertex2(x0, y1);

                    GL.End();
                    GL.Disable(EnableCap.Texture2D);
                }
                else
                {
                    GL.LineWidth(width);
                    GL.Begin(BeginMode.LineLoop);
                    GL.Vertex2(x0, y0);
                    GL.Vertex2(x1, y0);
                    GL.Vertex2(x1, y1);
                    GL.Vertex2(x0, y1);
                    GL.End();
                }
            }
            GL.PopMatrix();
        }
示例#11
0
        public void DrawLine(float x0, float y0, float x1, float y1, GLBrush brush, float width = 1.0f)
        {
            GL.PushMatrix();
            AddHalfPixelOffset();
            GL.Color4(brush.Color0);
            if (antialiasing)
            {
                GL.Enable(EnableCap.LineSmooth);
            }
#if FAMISTUDIO_LINUX
            if (!supportsLineWidth && width > 1)
            {
                DrawThickLineAsPolygon(new[] {
                    x0, y0,
                    x1, y1
                }, brush, width);
            }
            else
#endif
            {
                if (brush.IsBitmap)
                {
                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, brush.Bitmap.Id);
                    GL.LineWidth(width);
                    GL.Begin(BeginMode.Lines);

                    var size = brush.Bitmap.Size;
                    GL.TexCoord2((x0 + 0.5f) / size.Width, (y0 + 0.5f) / size.Height);
                    GL.Vertex2(x0, y0);
                    GL.TexCoord2((x1 + 0.5f) / size.Width, (y1 + 0.5f) / size.Height);
                    GL.Vertex2(x1, y1);

                    GL.End();
                    GL.Disable(EnableCap.Texture2D);
                }
                else
                {
                    GL.LineWidth(width);
                    GL.Begin(BeginMode.Lines);
                    GL.Vertex2(x0, y0);
                    GL.Vertex2(x1, y1);
                    GL.End();
                }
            }
            if (antialiasing)
            {
                GL.Disable(EnableCap.LineSmooth);
            }
            GL.PopMatrix();
        }
示例#12
0
        public void DrawGeometry(GLGeometry geo, GLBrush brush, float lineWidth = 1.0f)
        {
            GL.PushMatrix();
            if (lineWidth == 1.0f)
            {
                AddHalfPixelOffset();
            }
            GL.Enable(EnableCap.LineSmooth);
            GL.Color4(brush.Color0);
#if FAMISTUDIO_LINUX
            if (!supportsLineWidth && lineWidth > 1)
            {
                var pts = new float[geo.Points.Length * 2 + (geo.Closed ? 2 : 0)];
                for (int i = 0; i < geo.Points.GetLength(0); i++)
                {
                    pts[i * 2 + 0] = geo.Points[i, 0];
                    pts[i * 2 + 1] = geo.Points[i, 1];
                }

                if (geo.Closed)
                {
                    pts[geo.Points.Length * 2 + 0] = geo.Points[0, 0];
                    pts[geo.Points.Length * 2 + 1] = geo.Points[0, 1];
                }

                DrawThickLineAsPolygon(pts, brush, lineWidth);
            }
            else
#endif
            {
                GL.LineWidth(lineWidth);
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.VertexPointer(2, VertexPointerType.Float, 0, geo.Points);
                GL.DrawArrays(geo.Closed ? BeginMode.LineLoop : BeginMode.LineStrip, 0, geo.Points.GetLength(0));
                GL.DisableClientState(ArrayCap.VertexArray);
            }
            GL.Disable(EnableCap.LineSmooth);
            GL.PopMatrix();
        }
示例#13
0
        protected void DrawThickLineAsPolygon(float[] points, GLBrush brush, float width)
        {
            GL.Begin(BeginMode.Quads);
            for (int i = 0; i < points.Length / 2 - 1; i++)
            {
                float x0 = points[(i + 0) * 2 + 0];
                float y0 = points[(i + 0) * 2 + 1];
                float x1 = points[(i + 1) * 2 + 0];
                float y1 = points[(i + 1) * 2 + 1];

                float dx           = x1 - x0;
                float dy           = y1 - y0;
                float invHalfWidth = (width * 0.5f) / (float)Math.Sqrt(dx * dx + dy * dy);
                dx *= invHalfWidth;
                dy *= invHalfWidth;

                GL.Vertex2(x0 + dy, y0 + dx);
                GL.Vertex2(x1 + dy, y1 + dx);
                GL.Vertex2(x1 - dy, y1 - dx);
                GL.Vertex2(x0 - dy, y0 - dx);
            }
            GL.End();
        }
示例#14
0
        public void FillGeometry(GLGeometry geo, GLBrush brush, bool smooth = false)
        {
            if (!brush.IsGradient)
            {
                if (smooth)
                {
                    GL.Enable(EnableCap.PolygonSmooth);
                }
                GL.Color4(brush.Color0);
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.VertexPointer(2, VertexPointerType.Float, 0, geo.Points);
                GL.DrawArrays(BeginMode.TriangleFan, 0, geo.Points.GetLength(0));
                GL.DisableClientState(ArrayCap.VertexArray);
                if (smooth)
                {
                    GL.Disable(EnableCap.PolygonSmooth);
                }
            }
            else
            {
                Debug.Assert(brush.GradientSizeX == 0.0f);

                GL.Begin(BeginMode.TriangleFan);
                for (int i = 0; i < geo.Points.GetLength(0); i++)
                {
                    float lerp = geo.Points[i, 1] / (float)brush.GradientSizeY;
                    byte  r    = (byte)(brush.Color0.R * (1.0f - lerp) + (brush.Color1.R * lerp));
                    byte  g    = (byte)(brush.Color0.G * (1.0f - lerp) + (brush.Color1.G * lerp));
                    byte  b    = (byte)(brush.Color0.B * (1.0f - lerp) + (brush.Color1.B * lerp));
                    byte  a    = (byte)(brush.Color0.A * (1.0f - lerp) + (brush.Color1.A * lerp));

                    GL.Color4(r, g, b, a);
                    GL.Vertex2(geo.Points[i, 0], geo.Points[i, 1]);
                }
                GL.End();
            }
        }
示例#15
0
 public void FillAndDrawRectangle(float x0, float y0, float x1, float y1, GLBrush fillBrush, GLBrush lineBrush, float width = 1.0f)
 {
     FillRectangle(x0, y0, x1, y1, fillBrush);
     DrawRectangle(x0, y0, x1, y1, lineBrush, width);
 }
示例#16
0
        public void FillRectangle(float x0, float y0, float x1, float y1, GLBrush brush)
        {
            if (!brush.IsGradient)
            {
                GL.Color4(brush.Color0);
                GL.Begin(BeginMode.Quads);
                GL.Vertex2(x0, y0);
                GL.Vertex2(x1, y0);
                GL.Vertex2(x1, y1);
                GL.Vertex2(x0, y1);
                GL.End();
            }
            else if (brush.GradientSizeX == (x1 - x0))
            {
                GL.Begin(BeginMode.Quads);
                GL.Color4(brush.Color0); GL.Vertex2(x0, y0);
                GL.Color4(brush.Color1); GL.Vertex2(x1, y0);
                GL.Color4(brush.Color1); GL.Vertex2(x1, y1);
                GL.Color4(brush.Color0); GL.Vertex2(x0, y1);
                GL.End();
            }
            else if (brush.GradientSizeY == (y1 - y0))
            {
                GL.Begin(BeginMode.Quads);
                GL.Color4(brush.Color0); GL.Vertex2(x0, y0);
                GL.Color4(brush.Color0); GL.Vertex2(x1, y0);
                GL.Color4(brush.Color1); GL.Vertex2(x1, y1);
                GL.Color4(brush.Color1); GL.Vertex2(x0, y1);
                GL.End();
            }
            else if (brush.GradientSizeY == 0.0f)
            {
                float xm = x0 + brush.GradientSizeX;

                GL.Begin(BeginMode.Quads);
                GL.Color4(brush.Color0); GL.Vertex2(x0, y0);
                GL.Color4(brush.Color1); GL.Vertex2(xm, y0);
                GL.Color4(brush.Color1); GL.Vertex2(xm, y1);
                GL.Color4(brush.Color0); GL.Vertex2(x0, y1);
                GL.Color4(brush.Color1); GL.Vertex2(xm, y0);
                GL.Color4(brush.Color1); GL.Vertex2(x1, y0);
                GL.Color4(brush.Color1); GL.Vertex2(x1, y1);
                GL.Color4(brush.Color1); GL.Vertex2(xm, y1);
                GL.End();
            }
            else if (brush.GradientSizeX == 0.0f)
            {
                float ym = y0 + brush.GradientSizeY;

                GL.Begin(BeginMode.Quads);
                GL.Color4(brush.Color0); GL.Vertex2(x0, y0);
                GL.Color4(brush.Color1); GL.Vertex2(x0, ym);
                GL.Color4(brush.Color1); GL.Vertex2(x1, ym);
                GL.Color4(brush.Color0); GL.Vertex2(x1, y0);
                GL.Color4(brush.Color1); GL.Vertex2(x0, ym);
                GL.Color4(brush.Color1); GL.Vertex2(x0, y1);
                GL.Color4(brush.Color1); GL.Vertex2(x1, y1);
                GL.Color4(brush.Color1); GL.Vertex2(x1, ym);
                GL.End();
            }
        }
示例#17
0
 public void FillRectangle(RectangleF rect, GLBrush brush)
 {
     FillRectangle(rect.Left, rect.Top, rect.Right, rect.Bottom, brush);
 }
示例#18
0
 public void DrawRectangle(RectangleF rect, GLBrush brush, float width = 1.0f)
 {
     DrawRectangle(rect.Left, rect.Top, rect.Right, rect.Bottom, brush, width);
 }
示例#19
0
 public void FillAndDrawConvexPath(GLConvexPath geo, GLBrush fillBrush, GLBrush lineBrush, float lineWidth = 1.0f)
 {
     FillConvexPath(geo, fillBrush);
     DrawConvexPath(geo, lineBrush, lineWidth);
 }
示例#20
0
 public void FillAndDrawGeometry(GLGeometry geo, GLBrush fillBrush, GLBrush lineBrush, float lineWidth = 1.0f)
 {
     FillGeometry(geo, fillBrush);
     DrawGeometry(geo, lineBrush, lineWidth);
 }