/// <summary> /// 颜色转ushort /// </summary> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> /// <returns>ushort</returns> public static ushort ColourToUshort(Colour foreColor, Colour backColor) { return((ushort)((int)backColor * 16 + (int)foreColor)); }
/// <summary> /// ushort转颜色 /// </summary> /// <param name="attribute">ushort</param> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> public static void UshortToColour(ushort attribute, out Colour foreColor, out Colour backColor) { foreColor = (Colour)(attribute & 0x000F); backColor = (Colour)((attribute & 0x00F0) / 16); }
/// <summary> /// 根据字符串数组设置图形网格集合(适用于双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="strs">字符串</param> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> public void SetGridByStrings(Vector2 position, string[] strs, Colour foreColor, Colour backColor) { for (int i = 0; i < strs.Length; i++) { Vector2 pos = new Vector2(position.X, position.Y + i); SetGridByString(pos, strs[i], foreColor, backColor); } }
/// <summary> /// 根据数组设置图形网格集合(适用于单宽与双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="strs">字符串</param> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> public void SetGridByArray2D(Vector2 position, string[,] strs, Colour foreColor, Colour backColor) { for (int i = 0; i < strs.GetLength(0); i++) { for (int j = 0; j < strs.GetLength(1); j++) { Vector2 pos = new Vector2(position.X + j, position.Y + i); string str = strs[i, j]; if (str.Length == 1) { SetGrid(pos, new CharInfo(str[0], foreColor, backColor)); } else if (str.Length == 2) { SetGrid(pos, new CharInfo(str[0], foreColor, backColor), new CharInfo(str[1], foreColor, backColor)); } } } }
/// <summary> /// 根据数组创建图形网格集合(适用于单宽与双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="strs">字符串数组</param> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> /// <param name="depth">深度</param> /// <returns>图形网格集合</returns> public List <GraphicGrid> CreatGridByArray2D(Vector2 position, string[,] strs, Colour foreColor, Colour backColor, uint depth = 0) { List <GraphicGrid> graphicGrids = new List <GraphicGrid>(); for (int i = 0; i < strs.GetLength(0); i++) { for (int j = 0; j < strs.GetLength(1); j++) { GraphicGrid graphicGrid = null; Vector2 pos = new Vector2(position.X + j, position.Y + i); string str = strs[i, j]; if (str.Length == 1) { graphicGrid = CreatGrid(pos, new CharInfo(str[0], foreColor, backColor), depth); } else if (str.Length == 2) { graphicGrid = CreatGrid ( pos, new CharInfo(str[0], foreColor, backColor), new CharInfo(str[1], foreColor, backColor), depth ); } graphicGrids.Add(graphicGrid); } } return(graphicGrids); }
/// <summary> /// 创建矩形(适用于单宽与双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="size">尺寸</param> /// <param name="borderSize">边框尺寸</param> /// <param name="inside">内部填充字符串</param> /// <param name="insideForeColor">内部填充字符串前景色</param> /// <param name="insideBackColor">内部填充字符串背景色</param> /// <param name="border">边框填充字符串</param> /// <param name="borderForeColor">边框填充字符串前景色</param> /// <param name="borderBackColor">边框填充字符串背景色</param> /// <param name="insideGraphicGrids">内部填充图形网格集合</param> /// <param name="borderGraphicGrids">边框填充图形网格集合</param> /// <param name="depth">深度</param> public void CreatRectangle ( Vector2 position, Vector2 size, Vector2 borderSize, string inside, Colour insideForeColor, Colour insideBackColor, string border, Colour borderForeColor, Colour borderBackColor, out List <GraphicGrid> insideGraphicGrids, out List <GraphicGrid> borderGraphicGrids, uint depth = 0 ) { insideGraphicGrids = new List <GraphicGrid>(); borderGraphicGrids = new List <GraphicGrid>(); for (int i = 0; i < size.Y; i++) { for (int j = 0; j < size.X; j++) { GraphicGrid graphicGrid = null; Vector2 pos = new Vector2(position.X + j, position.Y + i); if (i >= 0 && i < borderSize.Y || j >= 0 && j < borderSize.X || i <= size.Y - 1 && i > size.Y - 1 - borderSize.Y || j <= size.X - 1 && j > size.X - 1 - borderSize.X) { if (border.Length == 1) { graphicGrid = CreatGrid ( pos, new CharInfo(border[0], borderForeColor, borderBackColor), depth ); } else if (border.Length == 2) { graphicGrid = CreatGrid ( pos, new CharInfo(border[0], borderForeColor, borderBackColor), new CharInfo(border[1], borderForeColor, borderBackColor), depth ); } borderGraphicGrids.Add(graphicGrid); } else { if (inside.Length == 1) { graphicGrid = CreatGrid ( pos, new CharInfo(inside[0], insideForeColor, insideBackColor), depth ); } else if (inside.Length == 2) { graphicGrid = CreatGrid ( pos, new CharInfo(inside[0], insideForeColor, insideBackColor), new CharInfo(inside[1], insideForeColor, insideBackColor), depth ); } insideGraphicGrids.Add(graphicGrid); } } } }
/// <summary> /// 根据字符串数组创建图形网格集合(适用于双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="strs">字符串数组</param> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> /// <param name="depth">深度</param> /// <returns>图形网格集合</returns> public List <GraphicGrid> CreatGridByStrings(Vector2 position, string[] strs, Colour foreColor, Colour backColor, uint depth = 0) { List <GraphicGrid> graphicGrids = new List <GraphicGrid>(); for (int i = 0; i < strs.Length; i++) { Vector2 pos = new Vector2(position.X, position.Y + i); List <GraphicGrid> grids = CreatGridByString(pos, strs[i], foreColor, backColor, depth); graphicGrids.AddRange(grids); } return(graphicGrids); }
/// <summary> /// 根据字符串创建图形网格集合(适用于双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="str">字符串</param> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> /// <param name="depth">深度</param> /// <returns>图形网格集合</returns> public List <GraphicGrid> CreatGridByString(Vector2 position, string str, Colour foreColor, Colour backColor, uint depth = 0) { List <string> strGrids = DivideStringToGrids(str); List <GraphicGrid> graphicGrids = new List <GraphicGrid>(); for (int i = 0; i < strGrids.Count; i++) { string item = strGrids[i]; GraphicGrid graphicGrid = null; Vector2 pos = new Vector2(position.X + i, position.Y); if (item.Length == 1) { graphicGrid = CreatGrid(pos, new CharInfo(item[0], foreColor, backColor), depth); } else if (item.Length == 2) { graphicGrid = CreatGrid(pos, new CharInfo(item[0], foreColor, backColor), new CharInfo(item[1], foreColor, backColor), depth); } graphicGrids.Add(graphicGrid); } return(graphicGrids); }
/// <summary> /// 根据字符串创建图形网格集合(适用于单宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="str">字符串</param> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> /// <param name="depth">深度</param> /// <returns>图形网格集合</returns> public List <GraphicGrid> CreatGridByString1(Vector2 position, string str, Colour foreColor, Colour backColor, uint depth = 0) { List <GraphicGrid> graphicGrids = new List <GraphicGrid>(); for (int i = 0; i < str.Length; i++) { char item = str[i]; GraphicGrid graphicGrid = null; Vector2 pos = new Vector2(position.X + i, position.Y); graphicGrid = CreatGrid(pos, new CharInfo(item, foreColor, backColor), depth); graphicGrids.Add(graphicGrid); } return(graphicGrids); }
/// <summary> /// 设置图形网格的颜色(会同时修改Left与Right属性的颜色) /// </summary> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> public void SetColor(Colour foreColor, Colour backColor) { Left.SetColor(foreColor, backColor); Right.SetColor(foreColor, backColor); }
/// <summary> /// 设置矩形(适用于单宽与双宽模式) /// </summary> /// <param name="position">坐标</param> /// <param name="size">尺寸</param> /// <param name="str">填充字符串</param> /// <param name="foreColor">前景色</param> /// <param name="backColor">背景色</param> public void SetRectangle(Vector2 position, Vector2 size, string str, Colour foreColor, Colour backColor) { for (int i = 0; i < size.Y; i++) { for (int j = 0; j < size.X; j++) { Vector2 pos = new Vector2(position.X + j, position.Y + i); if (str.Length == 1) { SetGrid(pos, new CharInfo(str[0], foreColor, backColor)); } else if (str.Length == 2) { SetGrid(pos, new CharInfo(str[0], foreColor, backColor), new CharInfo(str[1], foreColor, backColor)); } } } }