public static Gdk.Region RectanglesToRegion(Gdk.Rectangle[] rects) { Gdk.Region reg = Gdk.Region.Rectangle(Gdk.Rectangle.Zero); foreach (Gdk.Rectangle r in rects) { reg.UnionWithRect(r); } return(reg); }
/// <summary> /// Render the bytes in the highlight range. /// </summary> /// <param name="h"> /// A <see cref="Highlight"/> /// </param> /// <param name="merge"> /// Whether to visually merge the highlight with adjacent ones left and/or right. /// </param> /// <remarks> /// This method doesn't check whether the merge flags are correct (eg there is indeed /// a similar adjacent highlight). It just draws the highlight in such a way as /// to appear merged to any similar highlights if they exist. ///</remarks> internal protected virtual void RenderHighlight(Highlight h, Drawer.HighlightType left, Drawer.HighlightType right) { if (isAreaRealized == false) { return; } int rstart, bstart, xstart, ystart; int rend, bend, xend, yend; bool odd; Gdk.GC gc; Gdk.GC oddGC; Gdk.GC evenGC; Gdk.GC leftGC; Gdk.GC rightGC; oddGC = drawer.GetBackgroundGC(Drawer.RowType.Odd, h.Type); evenGC = drawer.GetBackgroundGC(Drawer.RowType.Even, h.Type); GetDisplayInfoByOffset(h.Start, out rstart, out bstart, out xstart, out ystart); GetDisplayInfoByOffset(h.End, out rend, out bend, out xend, out yend); //System.Console.WriteLine("Start {0:x} {1} {2} x:{3} y:{4}", h.Start, rstart, bstart, xstart, ystart); //System.Console.WriteLine("End {0:x} {1} {2} x:{3} y:{4}", h.End, rend, bend, xend, yend); bool drawLeft = false; int dxstart = xstart; if (bstart > 0) { int digit; GetOffsetFlags gof; GetOffsetByDisplayInfo(xstart - 1, ystart, out digit, out gof); if ((gof & GetOffsetFlags.Abyss) != 0) { dxstart -= drawer.Width; drawLeft = true; } } bool drawRight = false; int dxend = xend; if (bend < bpr - 1) { int digit; GetOffsetFlags gof; GetOffsetByDisplayInfo(xend + dpb * drawer.Width, yend, out digit, out gof); if ((gof & GetOffsetFlags.Abyss) != 0) { dxend += drawer.Width; drawRight = true; } } // if the whole range is on one row if (rstart == rend) { if (areaGroup.ManualDoubleBuffer) { BeginPaint(x + dxstart, y + ystart, dxend - dxstart + dpb * drawer.Width, drawer.Height); } // odd row? odd = (((h.Start / bpr) % 2) == 1); if (odd) { gc = oddGC; leftGC = drawer.GetBackgroundGC(Drawer.RowType.Odd, left); rightGC = drawer.GetBackgroundGC(Drawer.RowType.Odd, right); } else { gc = evenGC; leftGC = drawer.GetBackgroundGC(Drawer.RowType.Even, left); rightGC = drawer.GetBackgroundGC(Drawer.RowType.Even, right); } //render if (drawLeft) { backPixmap.DrawRectangle(leftGC, true, x + dxstart, y + ystart, drawer.Width, drawer.Height); } if (drawRight) { backPixmap.DrawRectangle(rightGC, true, x + xend + dpb * drawer.Width, y + yend, drawer.Width, drawer.Height); } backPixmap.DrawRectangle(gc, true, x + xstart, y + ystart, xend - xstart + dpb * drawer.Width, drawer.Height); RenderRangeHelper(h.Type, rstart, bstart, bend - bstart + 1); } else // multi-row range { if (areaGroup.ManualDoubleBuffer) { // handle double-buffering Gdk.Region paintRegion = new Gdk.Region(); Gdk.Rectangle rectStart = new Gdk.Rectangle(x + dxstart, y + ystart, width - dxstart, drawer.Height); Gdk.Rectangle rectMiddle; if (rend > rstart + 1) { rectMiddle = new Gdk.Rectangle(x, y + ystart + drawer.Height, width, yend - ystart - drawer.Height); } else { rectMiddle = Gdk.Rectangle.Zero; } Gdk.Rectangle rectEnd = new Gdk.Rectangle(x, y + yend, dxend + dpb * drawer.Width, drawer.Height); paintRegion.UnionWithRect(rectStart); paintRegion.UnionWithRect(rectMiddle); paintRegion.UnionWithRect(rectEnd); BeginPaintRegion(paintRegion); } // render first row odd = (((h.Start / bpr) % 2) == 1); if (odd) { gc = oddGC; leftGC = drawer.GetBackgroundGC(Drawer.RowType.Odd, left); rightGC = drawer.GetBackgroundGC(Drawer.RowType.Odd, right); } else { gc = evenGC; leftGC = drawer.GetBackgroundGC(Drawer.RowType.Even, left); rightGC = drawer.GetBackgroundGC(Drawer.RowType.Even, right); } if (drawLeft) { backPixmap.DrawRectangle(leftGC, true, x + dxstart, y + ystart, drawer.Width, drawer.Height); } backPixmap.DrawRectangle(gc, true, x + xstart, y + ystart, width - xstart, drawer.Height); RenderRangeHelper(h.Type, rstart, bstart, bpr - bstart); long curOffset = h.Start + bpr - bstart; // render middle rows for (int i = rstart + 1; i < rend; i++) { odd = (((curOffset / bpr) % 2) == 1); if (odd) { gc = oddGC; } else { gc = evenGC; } backPixmap.DrawRectangle(gc, true, x, y + i * drawer.Height, width, drawer.Height); RenderRangeHelper(h.Type, i, 0, bpr); curOffset += bpr; } // render last row odd = (((h.End / bpr) % 2) == 1); if (odd) { gc = oddGC; leftGC = drawer.GetBackgroundGC(Drawer.RowType.Odd, left); rightGC = drawer.GetBackgroundGC(Drawer.RowType.Odd, right); } else { gc = evenGC; leftGC = drawer.GetBackgroundGC(Drawer.RowType.Even, left); rightGC = drawer.GetBackgroundGC(Drawer.RowType.Even, right); } if (drawRight) { backPixmap.DrawRectangle(rightGC, true, x + xend + dpb * drawer.Width, y + yend, drawer.Width, drawer.Height); } backPixmap.DrawRectangle(gc, true, x, y + yend, xend + dpb * drawer.Width, drawer.Height); RenderRangeHelper(h.Type, rend, 0, bend + 1); } if (areaGroup.ManualDoubleBuffer) { EndPaint(); } }