using System;
using System.Collections.Generic;
using System.Text;
using DrawGraph;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace DrawGraph
{
    public class Util
    {
        public static FontSpec Font16 = new FontSpec("宋体", 16.0f, Color.Black, true, false, false);
         
        public static void DrawText(string letter, double x, double y, ZedGraphControl zedGraph, FontSpec font)
        {
            TextObj text = new TextObj(letter, x, y, CoordType.PaneFraction);
            text.FontSpec = font;
            text.FontSpec.Border.IsVisible = false;
            text.FontSpec.Fill.IsVisible = false;
            text.Location.AlignH = AlignH.Left;
            text.Location.AlignV = AlignV.Top;
            text.ZOrder = ZOrder.A_InFront;
            zedGraph.MasterPane.GraphObjList.Add(text);
        } 
        public static void DrawLine(double x1, double y1, double x2, double y2, ZedGraphControl zedGraph)
        {
            LineObj line = new LineObj(Color.Gray, x1, y1, x2, y2);
            line.IsVisible = true;
            line.ZOrder = ZOrder.A_InFront;
            line.Location.AlignH = AlignH.Left;
            line.Location.AlignV = AlignV.Top;
            line.Location.CoordinateFrame = CoordType.PaneFraction;
            zedGraph.MasterPane.GraphObjList.Add(line);
        }
         
        public static void DrawLine(double x1, double y1, double x2, double y2, ZedGraphControl zedGraph, string tag, Color LineColor)
        {
            LineObj lineObj = new LineObj(LineColor, x1, y1, x2, y2);
            lineObj.IsVisible = true;
            lineObj.ZOrder = ZOrder.A_InFront;
            lineObj.Location.AlignH = AlignH.Left;
            lineObj.Location.AlignV = AlignV.Top;
            lineObj.Location.CoordinateFrame = CoordType.PaneFraction;
            lineObj.Tag = tag;
            zedGraph.MasterPane.GraphObjList.Add(lineObj);
        }   
        /// 
        /// 在Zedgraph上绘图
        /// 
        /// 已定义好的ImageObj对象
        /// ZedGraphControl
        public static void DrawImage(ImageObj imgObj, ZedGraphControl zedGraph)
        {
            zedGraph.MasterPane.GraphObjList.Add(imgObj);
        }
        /// 
        /// 根据自定义好的TextObj绘制文字
        /// 
        /// 已定义的TextObj
        /// ZedGraphControl
        public static void DrawText(TextObj text, ZedGraphControl zedGraph)
        {
            zedGraph.MasterPane.GraphObjList.Add(text);
        }
        /// 
        /// 绘制矩形
        /// 
        /// 已定义的BoxObj对象
        /// ZedGraphControl
        public static void DrawBox(BoxObj box, ZedGraphControl zedGraph)
        {
            zedGraph.MasterPane.GraphObjList.Add(box);
        }
        /// 
        /// 画出带标签的线
        /// 
        /// 起点X坐标
        /// 起点Y坐标
        /// 终点X坐标
        /// 终点Y坐标
        /// ZedGraphControl
        /// 线标签
        public static void DrawLine(double x1, double y1, double x2, double y2, ZedGraphControl zedGraph, string tag, Color LineColor, DashStyle style = DashStyle.Solid)
        {
            LineObj line = new LineObj(LineColor, x1, y1, x2, y2);
            line.IsVisible = true;
            line.ZOrder = ZOrder.B_BehindLegend;
            line.Location.AlignH = AlignH.Left;
            line.Location.AlignV = AlignV.Top;
            line.Location.CoordinateFrame = CoordType.PaneFraction;
            line.Tag = tag;
            line.Line.Style = style;
            zedGraph.MasterPane.GraphObjList.Add(line);
        }
        /// 
        /// 获取TextObj字体的相对宽度
        /// 
        /// 
        /// 
        public static float GetColWidthFraction(TextObj text, ZedGraphControl zgc)
        {
            GraphPane pane = zgc.GraphPane;
            float ratio = pane.CalcScaleFactor();
            Graphics g = zgc.CreateGraphics();
            float absoluteWidth = text.FontSpec.GetWidth(g, text.Text, ratio);
            float paneWidth = pane.Rect.Width;
            return absoluteWidth / paneWidth;
        }
        /// 
        /// 获取TextObj字体的相对高度
        /// 
        /// 
        /// 
        /// 
        public static float GetColHeightFraction(TextObj text, ZedGraphControl zgc)
        {
            GraphPane pane = zgc.GraphPane;
            float ratio = pane.CalcScaleFactor();
            Graphics g = zgc.CreateGraphics();
            float absoluteHeight = text.FontSpec.GetHeight(ratio);
            float paneHeight = pane.Rect.Height;
            return absoluteHeight / paneHeight;
        }
        /////////////////////////////////////////////////////////////////////////
        public static void DrawLineWidth(double x1, double y1, double x2, double y2, ZedGraphControl zedGraph, string tag, Color LineColor, int width = 1)
        {
            LineObj line = new LineObj(LineColor, x1, y1, x2, y2);
            line.IsVisible = true;
            line.ZOrder = ZOrder.A_InFront;
            line.Location.AlignH = AlignH.Left;
            line.Location.AlignV = AlignV.Top;
            line.Location.CoordinateFrame = CoordType.PaneFraction;
            line.Tag = tag;
            line.Line.Style = DashStyle.Solid;
            line.Line.Width = width;
            zedGraph.MasterPane.GraphObjList.Add(line);
        }
    }
}