502 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			502 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
|  
 | ||
| using DrawGraph;
 | ||
| using Newtonsoft.Json;
 | ||
| using System;
 | ||
| using System.Collections.Generic;
 | ||
| using System.Configuration;
 | ||
| using System.Drawing; 
 | ||
| namespace DrawGraph
 | ||
| {
 | ||
| 	[JsonObject(MemberSerialization.OptOut)]
 | ||
| 	[Serializable]
 | ||
| 	public class TextPackObj : PackObjBase
 | ||
| 	{
 | ||
| 		private float fontSize = 8f;
 | ||
| 
 | ||
| 		private Color fontColor = Color.Black;
 | ||
| 
 | ||
| 		private ELineType isHorizontal = ELineType.Horizontal;
 | ||
| 
 | ||
| 		private EIsBool isUnderline = EIsBool.False;
 | ||
| 
 | ||
| 		private bool underline = false;
 | ||
| 
 | ||
| 		private int angle = 0;
 | ||
| 
 | ||
| 		private EIsBool isBool = EIsBool.False;
 | ||
| 
 | ||
| 		private int unit = 1;
 | ||
| 
 | ||
| 		private EIsBool isTop = EIsBool.True;
 | ||
| 
 | ||
| 		private string controlTitleText = "";
 | ||
| 
 | ||
| 		private float rowSpan = 0f;
 | ||
| 
 | ||
| 		private EIsBool isViewBoard = EIsBool.False;
 | ||
| 
 | ||
| 		private EAlignType alignType = EAlignType.Left;
 | ||
| 
 | ||
| 		private EIsBool isMultiline = EIsBool.False;
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "旋转角度", Description = "旋转角度")]
 | ||
| 		public int Angle
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.angle;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.angle = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "下划线", Description = "显示下划线")]
 | ||
| 		public EIsBool IsUnderline
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.isUnderline;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.isUnderline = value;
 | ||
| 				bool flag = this.isUnderline == EIsBool.True;
 | ||
| 				if (flag)
 | ||
| 				{
 | ||
| 					this.underline = true;
 | ||
| 				}
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "横向画", Description = "是否横向画")]
 | ||
| 		public ELineType IsHorizontal
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.isHorizontal;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.isHorizontal = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "文本字体", Description = "字体大小")]
 | ||
| 		public float FontSize
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.fontSize;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				bool flag = value > 2f && value < 24f;
 | ||
| 				if (flag)
 | ||
| 				{
 | ||
| 					this.fontSize = value;
 | ||
| 				}
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "下换行", Description = "多行时,换行向下画,反之向上画")]
 | ||
| 		public EIsBool IsTop
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.isTop;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.isTop = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "前景色", Description = "前景色")]
 | ||
| 		public Color FontColor
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.fontColor;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.fontColor = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "格式化文本", Description = "格式化字符串的样式")]
 | ||
| 		public string ControlTitleText
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.controlTitleText.Trim();
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.controlTitleText = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "加粗")]
 | ||
| 		public EIsBool IsBool
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.isBool;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.isBool = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "一行几个组件", Description = "最大单元数,文本框时:是有多少行;单选框或复选框:是一行放几个控件")]
 | ||
| 		public int Unit
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.unit;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.unit = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "行间距", Description = "行间距,值为0-1之间的值")]
 | ||
| 		public float RowSpan
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.rowSpan;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.rowSpan = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "显示边框", Description = "是否显示边框")]
 | ||
| 		public EIsBool IsViewBoard
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.isViewBoard;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.isViewBoard = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "文本对齐", Description = "文本对齐方式")]
 | ||
| 		public EAlignType AlignType
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.alignType;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.alignType = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		[ClassAttributs(CName = "多行", Description = "是否是多行,默认为FALSE单选")]
 | ||
| 		public EIsBool IsMultiline
 | ||
| 		{
 | ||
| 			get
 | ||
| 			{
 | ||
| 				return this.isMultiline;
 | ||
| 			}
 | ||
| 			set
 | ||
| 			{
 | ||
| 				this.isMultiline = value;
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		private float GetFontSize()
 | ||
| 		{
 | ||
| 			float result;
 | ||
| 			try
 | ||
| 			{
 | ||
| 				string text = null;// ConfigurationManager.AppSettings["FontSize"];
 | ||
| 				bool flag = text == null;
 | ||
| 				if (flag)
 | ||
| 				{
 | ||
| 					result = 8f;
 | ||
| 				}
 | ||
| 				else
 | ||
| 				{
 | ||
| 					result = float.Parse(text);
 | ||
| 				}
 | ||
| 			}
 | ||
| 			catch (Exception)
 | ||
| 			{
 | ||
| 				result = 8f;
 | ||
| 			}
 | ||
| 			return result;
 | ||
| 		}
 | ||
| 
 | ||
| 		public TextPackObj(ZedGraphControl zgc, PackObjManager poManager) : base(zgc, poManager)
 | ||
| 		{
 | ||
| 			this.baseZed = zgc;
 | ||
| 			base.PackText = "文本" + this.index.ToString();
 | ||
| 			this.fontSize = this.GetFontSize();
 | ||
| 		}
 | ||
| 
 | ||
| 		public override void Draw()
 | ||
| 		{
 | ||
| 			bool flag = this.baseZed == null;
 | ||
| 			if (!flag)
 | ||
| 			{
 | ||
| 				this.Clear();
 | ||
| 				base.PackText = base.PackText.Replace("\r", "\u3000").Replace("\n", "\u3000");
 | ||
| 				bool flag2 = this.IsHorizontal == ELineType.Horizontal;
 | ||
| 				if (flag2)
 | ||
| 				{
 | ||
| 					this.hDraw();
 | ||
| 				}
 | ||
| 				else
 | ||
| 				{
 | ||
| 					this.vDraw();
 | ||
| 				}
 | ||
| 				bool flag3 = this.isViewBoard == EIsBool.True;
 | ||
| 				if (flag3)
 | ||
| 				{
 | ||
| 					string packTag = base.PackTag + "_board";
 | ||
| 					RectangleFramePackObj rectangleFramePackObj = new RectangleFramePackObj(this.baseZed, this.poManager);
 | ||
| 					rectangleFramePackObj.PackTag = packTag;
 | ||
| 					float num = base.X;
 | ||
| 					bool flag4 = this.AlignType == EAlignType.Center;
 | ||
| 					if (flag4)
 | ||
| 					{
 | ||
| 						num -= base.Width / 2f;
 | ||
| 					}
 | ||
| 					rectangleFramePackObj.X = num;
 | ||
| 					rectangleFramePackObj.Y = base.Y;
 | ||
| 					rectangleFramePackObj.EndX = num + base.Width;
 | ||
| 					rectangleFramePackObj.EndY = base.Y + base.Height;
 | ||
| 					rectangleFramePackObj.Draw();
 | ||
| 				}
 | ||
| 				base.Refresh();
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		private void hDraw()
 | ||
| 		{
 | ||
| 			bool flag = base.PackText == "";
 | ||
| 			if (!flag)
 | ||
| 			{
 | ||
| 				bool flag2 = this.IsMultiline == EIsBool.False;
 | ||
| 				if (flag2)
 | ||
| 				{
 | ||
| 					TextObj textObj = this.CreateTextObj(base.PackText, base.PackTag);
 | ||
| 					Util.DrawText(textObj, this.baseZed);
 | ||
| 					this.width = Util.GetColWidthFraction(textObj, this.baseZed);
 | ||
| 					this.height = Util.GetColHeightFraction(textObj, this.baseZed);
 | ||
| 					base.EndX = base.X + this.width;
 | ||
| 					base.EndY = base.Y + this.height;
 | ||
| 				}
 | ||
| 				else
 | ||
| 				{
 | ||
| 					List<string> list = this.breakLinesForCanvas(base.PackText);
 | ||
| 					for (int i = 0; i < list.Count; i++)
 | ||
| 					{
 | ||
| 						string text = list[i];
 | ||
| 						double num = (double)base.RealY;
 | ||
| 						bool flag3 = this.IsTop == EIsBool.True;
 | ||
| 						if (flag3)
 | ||
| 						{
 | ||
| 							num = (double)(base.RealY + (float)i * this.RowSpan);
 | ||
| 						}
 | ||
| 						else
 | ||
| 						{
 | ||
| 							num = (double)(base.RealY - (float)(list.Count - i - 1) * this.RowSpan);
 | ||
| 						}
 | ||
| 						bool flag4 = text == "";
 | ||
| 						if (flag4)
 | ||
| 						{
 | ||
| 							break;
 | ||
| 						}
 | ||
| 						TextObj textObj2 = this.CreateTextObj(text, base.PackTag + "_" + i.ToString());
 | ||
| 						try
 | ||
| 						{
 | ||
| 							float colHeightFraction = Util.GetColHeightFraction(textObj2, this.baseZed);
 | ||
| 							bool flag5 = i == 0 && base.X == base.EndX;
 | ||
| 							if (flag5)
 | ||
| 							{
 | ||
| 								this.width = Util.GetColWidthFraction(textObj2, this.baseZed);
 | ||
| 								this.height = Util.GetColHeightFraction(textObj2, this.baseZed);
 | ||
| 							}
 | ||
| 							this.height = (float)num - base.RealY + colHeightFraction;
 | ||
| 							bool flag6 = base.X == base.EndX;
 | ||
| 							if (flag6)
 | ||
| 							{
 | ||
| 								base.EndX = base.X + this.width;
 | ||
| 								base.EndY = base.Y + this.height;
 | ||
| 							}
 | ||
| 						}
 | ||
| 						catch (Exception  )
 | ||
| 						{
 | ||
| 						}
 | ||
| 						textObj2.Location.X = (double)base.RealX;
 | ||
| 						textObj2.Location.Y = num;
 | ||
| 						Util.DrawText(textObj2, this.baseZed);
 | ||
| 					}
 | ||
| 				}
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		private int findBreakPoint(string text)
 | ||
| 		{
 | ||
| 			double num = 0.0;
 | ||
| 			double num2 = (double)(text.Length - 1);
 | ||
| 			int result;
 | ||
| 			try
 | ||
| 			{
 | ||
| 				bool flag = base.RealEndX != base.RealX;
 | ||
| 				if (flag)
 | ||
| 				{
 | ||
| 					while (num <= num2)
 | ||
| 					{
 | ||
| 						int num3 = Convert.ToInt32(Math.Floor((num + num2) / 2.0));
 | ||
| 						string a = text.Substring(0, num3);
 | ||
| 						bool flag2 = a != "";
 | ||
| 						if (!flag2)
 | ||
| 						{
 | ||
| 							result = -1;
 | ||
| 							return result;
 | ||
| 						}
 | ||
| 						TextObj text2 = this.CreateTextObj(text.Substring(0, num3), base.PackTag);
 | ||
| 						float colWidthFraction = Util.GetColWidthFraction(text2, this.baseZed);
 | ||
| 						TextObj text3 = this.CreateTextObj(text.Substring(0, num3 + 1), base.PackTag);
 | ||
| 						float colWidthFraction2 = Util.GetColWidthFraction(text3, this.baseZed);
 | ||
| 						float num4 = base.RealEndX - base.RealX + 0.0002f;
 | ||
| 						bool flag3 = colWidthFraction <= num4 && colWidthFraction2 > num4;
 | ||
| 						if (flag3)
 | ||
| 						{
 | ||
| 							result = num3;
 | ||
| 							return result;
 | ||
| 						}
 | ||
| 						bool flag4 = colWidthFraction < num4;
 | ||
| 						if (flag4)
 | ||
| 						{
 | ||
| 							num = (double)(num3 + 1);
 | ||
| 						}
 | ||
| 						else
 | ||
| 						{
 | ||
| 							num2 = (double)(num3 - 1);
 | ||
| 						}
 | ||
| 					}
 | ||
| 				}
 | ||
| 			}
 | ||
| 			catch (Exception  )
 | ||
| 			{
 | ||
| 				result = -1;
 | ||
| 				return result;
 | ||
| 			}
 | ||
| 			result = -1;
 | ||
| 			return result;
 | ||
| 		}
 | ||
| 
 | ||
| 		public List<string> breakLinesForCanvas(string text)
 | ||
| 		{
 | ||
| 			List<string> list = new List<string>();
 | ||
| 			int num;
 | ||
| 			while ((num = this.findBreakPoint(text)) != -1)
 | ||
| 			{
 | ||
| 				list.Add(text.Substring(0, num));
 | ||
| 				text = text.Substring(num);
 | ||
| 			}
 | ||
| 			bool flag = text != "";
 | ||
| 			if (flag)
 | ||
| 			{
 | ||
| 				list.Add(text);
 | ||
| 			}
 | ||
| 			return list;
 | ||
| 		}
 | ||
| 
 | ||
| 		private void vDraw()
 | ||
| 		{
 | ||
| 			for (int i = 0; i < base.PackText.Length; i++)
 | ||
| 			{
 | ||
| 				string text = base.PackText.Substring(i, 1);
 | ||
| 				bool flag = text.Trim() == "";
 | ||
| 				if (!flag)
 | ||
| 				{
 | ||
| 					float num = base.RealY + (float)i * this.RowSpan;
 | ||
| 					TextObj textObj = this.CreateTextObj(text, base.PackTag + "_" + i.ToString());
 | ||
| 					textObj.Location = new Location((double)base.RealX, (double)num, CoordType.PaneFraction);
 | ||
| 					Util.DrawText(textObj, this.baseZed);
 | ||
| 				}
 | ||
| 			}
 | ||
| 		}
 | ||
| 
 | ||
| 		private TextObj CreateTextObj(string packTextTemp, string packTag)
 | ||
| 		{
 | ||
| 			Color color = Color.FromArgb(this.fontColor.ToArgb());
 | ||
| 			bool isSelect = base.IsSelect;
 | ||
| 			if (isSelect)
 | ||
| 			{
 | ||
| 				color = Color.Red;
 | ||
| 			}
 | ||
| 			TextObj textObj = new TextObj(packTextTemp, (double)base.RealX, (double)base.RealY, CoordType.PaneFraction);
 | ||
| 			textObj.FontSpec = new FontSpec(PackObjBase.fontFamily, this.fontSize, color, this.isBool == EIsBool.True, false, this.underline);
 | ||
| 			textObj.FontSpec.Border.Width = 0f;
 | ||
| 			textObj.FontSpec.Border.IsVisible = false;
 | ||
| 			textObj.FontSpec.StringAlignment = StringAlignment.Near;
 | ||
| 			textObj.Tag = packTag;
 | ||
| 			textObj.FontSpec.Fill.IsVisible = false;
 | ||
| 			AlignH alignH = AlignH.Left;
 | ||
| 			bool flag = this.AlignType == EAlignType.Center;
 | ||
| 			if (flag)
 | ||
| 			{
 | ||
| 				alignH = AlignH.Center;
 | ||
| 			}
 | ||
| 			bool flag2 = this.AlignType == EAlignType.Right;
 | ||
| 			if (flag2)
 | ||
| 			{
 | ||
| 				alignH = AlignH.Right;
 | ||
| 			}
 | ||
| 			textObj.Location.AlignH = alignH;
 | ||
| 			textObj.Location.AlignV = AlignV.Top;
 | ||
| 			textObj.ZOrder = ZOrder.A_InFront;
 | ||
| 			textObj.FontSpec.Angle = (float)this.angle;
 | ||
| 			return textObj;
 | ||
| 		}
 | ||
| 
 | ||
| 		public override void Clear()
 | ||
| 		{
 | ||
| 			base.Clear();
 | ||
| 			for (int i = 0; i <= 20; i++)
 | ||
| 			{
 | ||
| 				string tag = base.PackTag + "_" + i.ToString();
 | ||
| 				bool flag = this.baseZed.MasterPane != null;
 | ||
| 				if (flag)
 | ||
| 				{
 | ||
| 					GraphObj graphObj = this.baseZed.MasterPane.GraphObjList[tag];
 | ||
| 					bool flag2 = graphObj != null;
 | ||
| 					if (flag2)
 | ||
| 					{
 | ||
| 						this.baseZed.MasterPane.GraphObjList.Remove(graphObj);
 | ||
| 					}
 | ||
| 				}
 | ||
| 			}
 | ||
| 			string tag2 = base.PackTag + "_board";
 | ||
| 			bool flag3 = this.baseZed.MasterPane != null;
 | ||
| 			if (flag3)
 | ||
| 			{
 | ||
| 				GraphObj graphObj2 = this.baseZed.MasterPane.GraphObjList[tag2];
 | ||
| 				bool flag4 = graphObj2 != null;
 | ||
| 				if (flag4)
 | ||
| 				{
 | ||
| 					this.baseZed.MasterPane.GraphObjList.Remove(graphObj2);
 | ||
| 				}
 | ||
| 			}
 | ||
| 		}
 | ||
| 	}
 | ||
| }
 |