/// <summary> /// 把 TailImage 與 Source Image 作合併 /// </summary> /// <param name="sourceImage">原始影像</param> /// <param name="tailImage">要接在原始影像後的影像</param> /// <param name="direction">合併方向</param> /// <returns></returns> public static HImage MergeTailImage(HImage sourceImage, HImage tailImage, MergeDirection direction) { HImage resultImage; HObject mergedImage, images; HOperatorSet.GenEmptyObj(out mergedImage); HOperatorSet.GenEmptyObj(out images); try { HTuple sWidth, sHeight, tWidth, tHeight; sourceImage.GetImageSize(out sWidth, out sHeight); tailImage.GetImageSize(out tWidth, out tHeight); HOperatorSet.ConcatObj(sourceImage, tailImage, out images); //產生參數 var param = genMergeParams(direction, sWidth, sHeight, tWidth, tHeight); //合併 HOperatorSet.TileImagesOffset(images, out mergedImage , param.offsetRow, param.offsetCol , param.row1, param.col1, param.row2, param.col2 , param.width, param.height); resultImage = mergedImage as HImage; if (resultImage == null) { var fpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), Guid.NewGuid().ToString()); HOperatorSet.WriteImage(mergedImage, "tiff", 0, fpath); var fpathWithExtension = fpath + ".tif"; resultImage = new HImage(fpath); if (File.Exists(fpathWithExtension)) File.Delete(fpathWithExtension); } } catch (HOperatorException ex) { logger.Error(ex); resultImage = null; } return resultImage; }
private static string rowValue = ""; //重新绘制的文本框内容 #region 单元格绘制合并 /// <summary> /// /// DataGridView合并单元格 /// </summary> /// <param name="dgv">要绘制的DataGridview</param> /// <param name="cellArgs">绘制单元格的参数(DataGridview的CellPainting事件中参数)</param> /// <param name="minColIndex">起始单元格在DataGridView中的索引号</param> /// <param name="maxColIndex">结束单元格在DataGridView中的索引号</param> /// <param name="kind">合并单元格的方向</param> public static void MerageCells(DataGridView dgv, DataGridViewCellPaintingEventArgs cellArgs, int minColIndex, int maxColIndex, MergeDirection kind) { int Index = kind == 0 ? cellArgs.ColumnIndex : cellArgs.RowIndex; if (Index < minColIndex || Index > maxColIndex) { return; } Rectangle rect = new Rectangle(); using (Brush gridBrush = new SolidBrush(dgv.GridColor), backColorBrush = new SolidBrush(cellArgs.CellStyle.BackColor)) { //抹去原来的cell背景 cellArgs.Graphics.FillRectangle(backColorBrush, cellArgs.CellBounds); } cellArgs.Handled = true; if (rowSpan[Index] == null) { //首先判断当前单元格是不是需要重绘的单元格 //保留此单元格的信息,并抹去此单元格的背景 rect.X = cellArgs.CellBounds.X; rect.Y = cellArgs.CellBounds.Y; rect.Width = cellArgs.CellBounds.Width; rect.Height = cellArgs.CellBounds.Height; if (Index == minColIndex) { rowValue = cellArgs.Value == null ? "" : cellArgs.Value.ToString(); } rowSpan.Add(Index, rect); if (Index != maxColIndex) { return; } MeragePrint(dgv, cellArgs, minColIndex, maxColIndex, kind); } else { if (Index == minColIndex) { rowValue = cellArgs.Value == null ? "" : cellArgs.Value.ToString(); } IsPostMerage(dgv, cellArgs, minColIndex, maxColIndex, kind); } }
/// <summary> /// 绘制单元格 /// </summary> /// <param name="dgv">要绘制的DataGridview</param> /// <param name="cellArgs">绘制单元格的参数(DataGridview的CellPainting事件中参数)</param> /// <param name="minColIndex">起始单元格在DataGridView中的索引号</param> /// <param name="maxColIndex">结束单元格在DataGridView中的索引号</param> /// <param name="kind">合并单元格的方向</param> private static void MeragePrint(DataGridView dgv, DataGridViewCellPaintingEventArgs cellArgs, int minColIndex, int maxColIndex, MergeDirection kind) { int length = 0; for (int i = minColIndex; i <= maxColIndex; i++) { length += kind == 0 ? ((Rectangle)rowSpan[i]).Width : ((Rectangle)rowSpan[i]).Height; } int width = kind == 0 ? length : cellArgs.CellBounds.Width; //合并后单元格总宽度 int height = kind == 0 ? cellArgs.CellBounds.Height : length; //合并后单元格总高度 Rectangle rectBegin = (Rectangle)rowSpan[minColIndex]; //合并第一个单元格的位置信息 Rectangle rectEnd = (Rectangle)rowSpan[maxColIndex]; //合并最后一个单元格的位置信息 //合并单元格的位置信息 Rectangle reBounds = new Rectangle(); reBounds.X = rectBegin.X; reBounds.Y = rectBegin.Y; reBounds.Width = width - 1; reBounds.Height = height - 1; using (Brush gridBrush = new SolidBrush(dgv.GridColor), backColorBrush = new SolidBrush(cellArgs.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { // 画出上下两条边线,左右边线无 Point blPoint = new Point(kind == 0 ? rectBegin.Left : rectEnd.Left, kind == 0 ? rectBegin.Bottom - 1 : rectEnd.Bottom - 1); //底线左边位置 Point brPoint = new Point(rectEnd.Right - 1, rectEnd.Bottom - 1); //底线右边位置 cellArgs.Graphics.DrawLine(gridLinePen, blPoint, brPoint); //下边线 Point tlPoint = new Point(rectBegin.Left, rectBegin.Top == 0 ? rectBegin.Top : rectBegin.Top - 1); //上边线左边位置 Point trPoint = new Point(kind == 0 ? rectEnd.Right - 1 : rectBegin.Right - 1, kind == 0 ? (rectEnd.Top == 0 ? rectEnd.Top : rectEnd.Top - 1) : (rectBegin.Top == 0 ? rectBegin.Top : rectBegin.Top - 1)); //上边线右边位置 cellArgs.Graphics.DrawLine(gridLinePen, tlPoint, trPoint); //上边线 Point ltPoint = new Point(rectBegin.Left == 0 ? rectBegin.Left : rectBegin.Left - 1, rectBegin.Top); //左边线顶部位置 Point lbPoint = new Point(kind == 0 ? (rectBegin.Left == 0 ? rectBegin.Left : rectBegin.Left - 1) : (rectEnd.Left == 0 ? rectEnd.Left : rectEnd.Left - 1), kind == 0 ? rectBegin.Bottom - 1 : rectEnd.Bottom - 1); //左边线底部位置 cellArgs.Graphics.DrawLine(gridLinePen, ltPoint, lbPoint); //左边线 Point rtPoint = new Point(kind == 0 ? rectEnd.Right - 1 : rectBegin.Right - 1, kind == 0 ? rectEnd.Top : rectBegin.Top); //右边线顶部位置 Point rbPoint = new Point(rectEnd.Right - 1, rectEnd.Bottom - 1); //右边线底部位置 cellArgs.Graphics.DrawLine(gridLinePen, rtPoint, rbPoint); //右边线 //计算绘制字符串的位置 SizeF sf = cellArgs.Graphics.MeasureString(rowValue, cellArgs.CellStyle.Font); //float lstr = (width - sf.Width) / 2; //水平居中 float lstr = 0; //左对齐 float rstr = (height - sf.Height) / 2; //垂直居中 //画出文本框 if (rowValue != "") { cellArgs.Graphics.DrawString(rowValue, cellArgs.CellStyle.Font, new SolidBrush(cellArgs.CellStyle.ForeColor), rectBegin.Left + lstr, rectBegin.Top + rstr, StringFormat.GenericDefault); } } cellArgs.Handled = true; } }
protected abstract CodeAction CreateCodeAction( Func <CancellationToken, Task <Document> > createChangedDocument, MergeDirection direction, string ifKeywordText);
private static string GetResourceText(MergeDirection direction) => direction == MergeDirection.Up ? FeaturesResources.Merge_with_previous_0_statement : FeaturesResources.Merge_with_next_0_statement;
protected sealed override CodeAction CreateCodeAction(Func <CancellationToken, Task <Document> > createChangedDocument, MergeDirection direction, string ifKeywordText) { var resourceText = direction == MergeDirection.Up ? FeaturesResources.Merge_with_previous_0_statement : FeaturesResources.Merge_with_next_0_statement; return(new MyCodeAction(string.Format(resourceText, ifKeywordText), createChangedDocument)); }
private void CopyItem(MergeDirection dir, int fromId, int toIndex) { switch (dir) { case MergeDirection.From_1to2 : throw new Exception("Данная функция не реализованна, используйте обратное объединение."); break; case MergeDirection.From_2to1 : if (!Ultima.Secondary.Art.IsValidStatic(fromId)) { Ultima.Art.RemoveStatic(toIndex); Ultima.RadarCol.SetItemColor(toIndex, 0x0421); Ultima.TileData.ItemTable[toIndex] = new ItemData(); } else { Ultima.Art.ReplaceStatic(toIndex, Ultima.Secondary.Art.GetStatic(fromId)); Ultima.RadarCol.SetItemColor(toIndex, Ultima.Secondary.RadarCol.GetItemColor(fromId)); Ultima.TileData.ItemTable[toIndex] = Ultima.Secondary.TileData.ItemTable[fromId]; } break; } }
private static string GetResourceText(MergeDirection direction) => direction == MergeDirection.Up ? FeaturesResources.Merge_with_outer_0_statement : FeaturesResources.Merge_with_nested_0_statement;
private static Dictionary <string, string> rowValue = new Dictionary <string, string>(); //重新绘制的文本框内容 #region 单元格绘制合并 /// <summary> /// /// DataGridView合并单元格 /// </summary> /// <param name="dgv">要绘制的DataGridview</param> /// <param name="cellArgs">绘制单元格的参数(DataGridview的CellPainting事件中参数)</param> /// <param name="minColIndex">起始单元格在DataGridView中的索引号</param> /// <param name="maxColIndex">结束单元格在DataGridView中的索引号</param> /// <param name="kind">合并单元格的方向</param> public static void MergeCells(DataGridView dgv, DataGridViewCellPaintingEventArgs cellArgs, int minColIndex, int maxColIndex, MergeDirection kind) { if (kind == MergeDirection.Horizontal) { MergeCells(dgv, cellArgs, new int[] { cellArgs.RowIndex, cellArgs.RowIndex, minColIndex, maxColIndex }); } else { MergeCells(dgv, cellArgs, new int[] { minColIndex, maxColIndex, cellArgs.ColumnIndex, cellArgs.ColumnIndex }); } }
/// <summary> /// 批量合并单元格(已知需要合并的单元格是连在一起的) /// </summary> /// <param name="dgv"></param> /// <param name="cellArgs"></param> /// <param name="indexArray"></param> /// <param name="kind"></param> public static void MergeCellsBatch(DataGridView dgv, DataGridViewCellPaintingEventArgs cellArgs, int[] indexArray, MergeDirection kind) { if (indexArray != null && indexArray.Length > 0) { for (int i = 0; i < indexArray.Length - 1; i++) { MergeCells(dgv, cellArgs, indexArray[i], indexArray[i + 1] - 1, MergeDirection.Horizontal); } MergeCells(dgv, cellArgs, indexArray[indexArray.Length - 1], dgv.Columns.Count - 1, MergeDirection.Horizontal); } }
/// <summary> /// 批量合并单元格(已知每个需要合并的单元格的标号) /// </summary> /// <param name="dgv"></param> /// <param name="cellArgs"></param> /// <param name="minColIndex"></param> /// <param name="maxColIndex"></param> /// <param name="kind"></param> public static void MergeCellsBatch(DataGridView dgv, DataGridViewCellPaintingEventArgs cellArgs, Point[] pointArray, MergeDirection kind) { if (pointArray != null && pointArray.Length > 0) { foreach (Point point in pointArray) { MergeCells(dgv, cellArgs, point.X, point.Y, MergeDirection.Horizontal); } } }
protected sealed override CodeAction CreateCodeAction(Func <CancellationToken, Task <Document> > createChangedDocument, MergeDirection direction, string ifKeywordText) { var resourceText = direction == MergeDirection.Up ? FeaturesResources.Merge_with_outer_0_statement : FeaturesResources.Merge_with_nested_0_statement; var title = string.Format(resourceText, ifKeywordText); return(CodeAction.Create(title, createChangedDocument, title)); }
private void SaveItems(MergeDirection dir) { switch (dir) { case MergeDirection.For_2 : throw new Exception("Данная функция не реализованна, используйте обратное объединение."); break; case MergeDirection.For_1 : string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; Ultima.Art.Save(path); Ultima.RadarCol.Save(Path.Combine(path, "radarcol.mul")); Ultima.TileData.SaveTileData(Path.Combine(path, "tiledata.mul")); MessageBox.Show(String.Format("Файлы: 'art.mul', 'artidx.mul', 'radarcol.mul', 'tiledata.mul' были сохранены в {0}", path), "Сохраннено", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); break; } }
private void ItemsAsImage(MergeDirection dir, ImageFormat format, bool hexnames = true) { string ext = String.Empty; if (format == ImageFormat.Bmp) ext = "bmp"; else if (format == ImageFormat.Png) ext = "png"; else if (format == ImageFormat.Gif) ext = "gif"; else if (format == ImageFormat.Tiff) ext = "tiff"; else if (format == ImageFormat.Jpeg) ext = "jpg"; else throw new ArgumentException(); using (FolderBrowserDialog dialog = new FolderBrowserDialog()) { dialog.Description = "Выберите папку"; dialog.ShowNewFolderButton = true; dialog.SelectedPath = m_LastFolder; if (dialog.ShowDialog() == DialogResult.OK) { m_LastFolder = dialog.SelectedPath; switch (dir) { case MergeDirection.For_1: if (format == ImageFormat.Gif) { foreach (int index in listViewItemSelected) if (Ultima.Art.IsValidStatic(index)) { string FileName = Path.Combine(dialog.SelectedPath, String.Format(hexnames ? "I0x{0:X4}.{1}" : "I{0:D5}.{1}", index, ext)); Bitmap bit = new Bitmap(Ultima.Art.GetStatic(index)); Utils.SaveGIFWithNewColorTable(bit, FileName, 256, true); } } else { foreach (int index in listViewItemSelected) if (Ultima.Art.IsValidStatic(index)) { string FileName = Path.Combine(dialog.SelectedPath, String.Format(hexnames ? "I0x{0:X4}.{1}" : "I{0:D5}.{1}", index, ext)); Bitmap bit = new Bitmap(Ultima.Art.GetStatic(index)); bit.Save(FileName, format); bit.Dispose(); } } break; case MergeDirection.For_2: if (format == ImageFormat.Gif) { foreach (int index in listViewItemSelected) if (Ultima.Secondary.Art.IsValidStatic(index)) { string FileName = Path.Combine(dialog.SelectedPath, String.Format(hexnames ? "I0x{0:X4}.{1}" : "I{0:D5}.{1}", index, ext)); Bitmap bit = new Bitmap(Ultima.Secondary.Art.GetStatic(index)); Utils.SaveGIFWithNewColorTable(bit, FileName, 256, true); } } else { foreach (int index in listViewItemSelected) if (Ultima.Secondary.Art.IsValidStatic(index)) { string FileName = Path.Combine(dialog.SelectedPath, String.Format(hexnames ? "I0x{0:X4}.{1}" : "I{0:D5}.{1}", index, ext)); Bitmap bit = new Bitmap(Ultima.Secondary.Art.GetStatic(index)); bit.Save(FileName, format); bit.Dispose(); } } break; default: throw new ArgumentException("Недопустимое значение MergeDirection"); } MessageBox.Show(String.Format("Все предметы были сохранены в {0}", dialog.SelectedPath), "Сохраненно", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } } }
/// <summary> /// 不是初次单元格绘制 /// </summary> /// <param name="dgv">要绘制的DataGridview</param> /// <param name="cellArgs">绘制单元格的参数(DataGridview的CellPainting事件中参数)</param> /// <param name="minColIndex">起始单元格在DataGridView中的索引号</param> /// <param name="maxColIndex">结束单元格在DataGridView中的索引号</param> /// <param name="kind">合并单元格的方向</param> public static void IsPostMerage(DataGridView dgv, DataGridViewCellPaintingEventArgs cellArgs, int minColIndex, int maxColIndex, MergeDirection kind) { int Index = kind == 0 ? cellArgs.ColumnIndex : cellArgs.RowIndex; //比较单元是否有变化 Rectangle rectArgs = (Rectangle)rowSpan[Index]; if (rectArgs.X != cellArgs.CellBounds.X || rectArgs.Y != cellArgs.CellBounds.Y || rectArgs.Width != cellArgs.CellBounds.Width || rectArgs.Height != cellArgs.CellBounds.Height) { rectArgs.X = cellArgs.CellBounds.X; rectArgs.Y = cellArgs.CellBounds.Y; rectArgs.Width = cellArgs.CellBounds.Width; rectArgs.Height = cellArgs.CellBounds.Height; rowSpan[Index] = rectArgs; } if (Index == maxColIndex) { MeragePrint(dgv, cellArgs, minColIndex, maxColIndex, kind); } }
public MyCodeAction(Func <CancellationToken, Task <Document> > createChangedDocument, MergeDirection direction, string ifKeywordText) : base(string.Format(GetResourceText(direction), ifKeywordText), createChangedDocument) { }
/// <summary> /// 產生合併用的參數 /// </summary> /// <param name="direction"></param> /// <param name="sWidth"></param> /// <param name="sHeight"></param> /// <param name="tWidth"></param> /// <param name="tHeight"></param> /// <returns></returns> private static MergeParamModel genMergeParams(MergeDirection direction, double sWidth, double sHeight, double tWidth, double tHeight) { HTuple row1 = new HTuple(new int[] { -1, -1 }); HTuple col1 = new HTuple(new int[] { -1, -1 }); HTuple row2 = new HTuple(new int[] { -1, -1 }); HTuple col2 = new HTuple(new int[] { -1, -1 }); double height = sHeight, width = sWidth; double[] offsetR = null, offsetC = null; MergeParamModel model = new MergeParamModel() { row1 = row1, col1 = col1, row2 = row2, col2 = col2, }; switch (direction) { case MergeDirection.Vertical: width = sWidth; height = sHeight + tHeight; offsetR = new double[] { 0, sHeight }; offsetC = new double[] { 0, 0 }; break; case MergeDirection.Horizontal: width = sWidth + tWidth; height = sHeight; offsetR = new double[] { 0, 0 }; offsetC = new double[] { 0, sWidth }; break; } model.height = new HTuple(height); model.width = new HTuple(width); model.offsetRow = new HTuple(offsetR); model.offsetCol = new HTuple(offsetC); return model; }
// Converts: // if (a) // { // if (b) // Console.WriteLine(); // } // // To: // if (a && b) // Console.WriteLine(); protected sealed override CodeAction CreateCodeAction(Func <CancellationToken, Task <Document> > createChangedDocument, MergeDirection direction, string ifKeywordText) => new MyCodeAction(createChangedDocument, direction, ifKeywordText);
private void Merge(int indexLeft, int indexRight, MergeDirection direction) { var left = lstLeft.Items[indexLeft]; var right = lstRight.Items[indexRight]; if (IsDemo) { switch (direction) { // Moving item from right and putting it left // case MergeDirection.Left: if (left.BackColor == LIGHT_NO_MATCH) { lstLeft.Items[indexLeft].Text = lstRight.Items[indexRight].Text; lstLeft.Items[indexLeft].ForeColor = Color.Black; lstLeft.Items[indexLeft].BackColor = ALL_GOOD; lstRight.Items[indexRight].BackColor = ALL_GOOD; } break; // Moving item from left and putting it right // case MergeDirection.Right: if (right.BackColor == LIGHT_NO_MATCH) { lstRight.Items[indexRight].Text = lstLeft.Items[indexLeft].Text; lstRight.Items[indexRight].ForeColor = Color.Black; lstRight.Items[indexLeft].BackColor = ALL_GOOD; lstLeft.Items[indexLeft].BackColor = ALL_GOOD; } break; } } else { } }