private void MergeGraph() { BorderObj BorderSet = Set.Border; Double FixBorder = 0; // TODO: Margin 背景区 MarginGraph = Enumerable.Repeat(Function.RepeatStr(" ", Set.Margin.Width), Set.Margin.Height).ToArray(); // TODO: Padding 背景区 PaddingGraph = Enumerable.Repeat(Function.RepeatStr(" ", Set.Padding.Width), Set.Padding.Height).ToArray(); // TODO: Border 背景区 BorderGraph = new String[BorderSet.Height]; Int32 CenterLen = 0, BorderLen = 0, MiddleLen = 0; String MiddleStr; // HACK: 手动调整至对齐顶部, 注意区分控制台模式 if (Set.OldConsole) { MiddleLen = Function.RawLength(BorderSet.Top); CenterLen = (BorderSet.Width - Function.RawLength(BorderSet.LeftTop) - Function.RawLength(BorderSet.RightTop)) / MiddleLen; BorderGraph[0] = BorderSet.LeftTop + Function.RepeatStr(BorderSet.Top, CenterLen) + BorderSet.RightTop; CenterLen = BorderSet.Width - Function.RawLength(BorderSet.Left) - Function.RawLength(BorderSet.Right); MiddleStr = BorderSet.Left + Function.RepeatStr(" ", CenterLen) + BorderSet.Right; for (Int32 i = 1; i < BorderSet.Height - 1; i++) { BorderGraph[i] = MiddleStr; } MiddleLen = Function.RawLength(BorderSet.Buttom); CenterLen = (BorderSet.Width - Function.RawLength(BorderSet.LeftButtom) - Function.RawLength(BorderSet.RightButtom)) / MiddleLen; BorderGraph[BorderSet.Height - 1] = BorderSet.LeftButtom + Function.RepeatStr(BorderSet.Buttom, CenterLen) + BorderSet.RightButtom; Boolean FixNeed = Function.RawLength(BorderGraph[0]) + Function.RawLength(BorderGraph.Last()) < 2 * BorderSet.Width; if (FixNeed) { BorderLen = Function.RawLength(BorderSet.Top); FixBorder = BorderSet.Width - Function.RawLength(BorderSet.LeftTop) - Function.RawLength(BorderSet.RightTop); FixBorder = (BorderLen * (Math.Ceiling(FixBorder / BorderLen) + 1) - FixBorder) % BorderLen; FixBorder = (Set.Padding.Right - Set.Padding.Left + FixBorder) % BorderLen + Set.Padding.Left; Console.SetCursorPosition(0, Set.Margin.Position.Top + Set.Margin.Height); Console.WriteLine("[INFO] 建议设置 Padding.Right = {0} + {1}x, x = 0,1,2...", FixBorder, BorderLen); } } else { MiddleLen = BorderSet.Top.Length; CenterLen = (BorderSet.Width - BorderSet.LeftTop.Length - BorderSet.RightTop.Length) / MiddleLen; BorderGraph[0] = BorderSet.LeftTop + Function.RepeatStr(BorderSet.Top, CenterLen) + BorderSet.RightTop; CenterLen = BorderSet.Width - BorderSet.Left.Length - BorderSet.Right.Length; MiddleStr = BorderSet.Left + Function.RepeatStr(" ", CenterLen) + BorderSet.Right; for (Int32 i = 1; i < BorderSet.Height - 1; i++) { BorderGraph[i] = MiddleStr; } MiddleLen = BorderSet.Buttom.Length; CenterLen = (BorderSet.Width - BorderSet.LeftButtom.Length - BorderSet.RightButtom.Length) / MiddleLen; BorderGraph[BorderSet.Height - 1] = BorderSet.LeftButtom + Function.RepeatStr(BorderSet.Buttom, CenterLen) + BorderSet.RightButtom; Boolean FixNeed = BorderGraph[0].Length + BorderGraph[BorderSet.Height - 1].Length < 2 * BorderSet.Width; if (FixNeed) { BorderLen = BorderSet.Top.Length; FixBorder = (BorderSet.Width - BorderGraph[0].Length) % BorderLen; Console.SetCursorPosition(0, Set.Margin.Position.Top + Set.Margin.Height); Console.Write("[INFO] 建议设置 Padding.Right = {0} + {1}x, x = 0,1,2...", FixBorder + Set.Padding.Left, BorderLen); } } // TODO: Content 背景区 ContentGraph = new String[Set.ContentSet.Row]; Int32 NowCnt = 0, Indent = 0, Differ = 0; String Str; for (Int32 Row = 0; Row < Set.ContentSet.Row; Row++) { Str = ""; for (Int32 Col = 0; Col < Set.ContentSet.Column; Col++) { NowCnt = Set.ContentSet.ByColumn ? Col * Set.ContentSet.Row + Row : Row * Set.ContentSet.Column + Col; Differ = NowCnt < Set.ContentSet.Count ? Set.ContentSet.ColWidth[Col] - Function.RawLength(Set.Content.Strings[NowCnt]) - Function.RawLength(Set.Content.Pointer) : 0; Indent = Set.ContentSet.ColIndent[Col] + (NowCnt < Set.ContentSet.Count ? Function.RawLength(Set.Content.Pointer) : 0); // Console.WriteLine("NowCount {0}, Col {1},Indent {2}", NowCount, Col, Indent); Str += Function.RepeatStr(" ", Indent) + (NowCnt < Set.ContentSet.Count ? Set.Content.Strings[NowCnt] : Set.Content.Flush[Col]) + Function.RepeatStr(" ", Differ); } ContentGraph[Row] = Str; } }
public void NewSet(Boolean oldconsole, Position pos, MarginPaddingObj marginobj, MarginPaddingObj paddingobj, BorderObj borderobj, ContentObj contentobj, ContentSetObj contentsetobj) { NewSet(oldconsole, pos); Margin = marginobj; Padding = paddingobj; Border = borderobj; Content = contentobj; ContentSet = contentsetobj; }