protected internal override void Render() { // obtain exclusive lock on backbuffer dc for GDI blit IntPtr hDC = _surface.Buffer.DC.GetHdc(); // if the tilesheet has a mask... if (_tilesheet.Mask != null) { // AND the mask Win32Support.DrawBitmap(hDC, _bounds, _tilesheet.Mask.hDC, new Rectangle(new Point(), _tilesheet.Bmp.Size), TernaryRasterOperations.SRCAND); // PAINT the primary Win32Support.DrawBitmap(hDC, _bounds, _tilesheet.hDC, new Rectangle(new Point(), _tilesheet.Bmp.Size), TernaryRasterOperations.SRCPAINT); } else { // straight COPY the primary Win32Support.DrawBitmap(hDC, _bounds, _tilesheet.hDC, new Rectangle(new Point(), _tilesheet.Bmp.Size), _rasterOp); } // release lock on backbuffer dc _surface.Buffer.DC.ReleaseHdc(hDC); }
public override void Erase() { IntPtr hDC = DC.GetHdc(); Win32Support.DrawBitmap(hDC, 0, 0, Width, Height, hDC, 0, 0, Width, Height, TernaryRasterOperations.BLACKNESS); DC.ReleaseHdc(hDC); }
private void CreateResizedGDIBitmap(Tilesheet origTilesheet, ref Bitmap newBmp, ref Graphics newGraphics, ref IntPtr hdc, ref IntPtr hbmp) { // create the new Bitmap object with the new stretched Size newBmp = new Bitmap(RenderSize.Width, RenderSize.Height); // get Graphics object from new Bitmap with new size newGraphics = Graphics.FromImage(newBmp); // get pointer to Graphics object for new Bitmap hdc = ResizedGraphics.GetHdc(); // create and get handle to a GDI bitmap object compatible with the GDI+ Bitmap hbmp = NewBmp.GetHbitmap(); // associate the new bitmap handle with the new Graphics handle pInvoke.SelectObject(hdc, hbmp); // draw (i.e., StretchBlt) to new Graphics object from original Frame Bitmap Win32Support.DrawBitmap(hdc, new Rectangle(0, 0, NewBmp.Width, NewBmp.Height), origTilesheet.hDC, origTilesheet.GetSourceRange(OriginalFrame.XTile, OriginalFrame.YTile), TernaryRasterOperations.SRCCOPY); // release the pointer to the Graphics Hdc ResizedGraphics.ReleaseHdc(hdc); }
internal void ResetScreenResolution() { // only reset if previously changed if (Screen.PrimaryScreen.Bounds != origRes) { Win32Support.SetScreenResolution(origRes.Size); } }
internal void SetScreenResolution(Size newSz) { // only call method if not the same size as it is currently if (Screen.PrimaryScreen.Bounds.Size != newSz) { Win32Support.SetScreenResolution(newSz); } }
public void Erase(Rectangle pxlRange) { IntPtr hDC = dc.GetHdc(); pxlRange = Rectangle.Intersect(pxlRange, range); Win32Support.DrawBitmap(hDC, pxlRange, hDC, pxlRange, TernaryRasterOperations.BLACKNESS); AddToDirtyRectangle(pxlRange); dc.ReleaseHdc(hDC); }
private void RenderBackbufferAll() { IntPtr hDC = DC.GetHdc(); IntPtr hDCBuffer = Buffer.DC.GetHdc(); Win32Support.DrawBitmap(hDC, 0, 0, Width, Height, hDCBuffer, 0, 0, Width, Height, TernaryRasterOperations.SRCCOPY); DC.ReleaseHdc(hDC); Buffer.DC.ReleaseHdc(hDCBuffer); }
public void SaveToFile(string file) { Bitmap toSave = new Bitmap(range.Width, range.Height, dc); Graphics graphics = Graphics.FromImage(toSave); IntPtr graphicsDC = graphics.GetHdc(); IntPtr hDC = dc.GetHdc(); Win32Support.DrawBitmap(graphicsDC, range, hDC, range, TernaryRasterOperations.SRCCOPY); dc.ReleaseHdc(hDC); graphics.ReleaseHdc(graphicsDC); toSave.Save(file); graphics.Dispose(); toSave.Dispose(); }
private void AFCPanel_Paint(object sender, PaintEventArgs e) { if (memDC != null) { IntPtr hdc = e.Graphics.GetHdc(); IntPtr hMemdc = memDC.GetHdc(); Win32Support.BitBlt(hdc, 0, 0, this.Width, this.Height, hMemdc, 0, 0, Win32Support.TernaryRasterOperations.SRCCOPY); e.Graphics.ReleaseHdc(hdc); memDC.ReleaseHdc(hMemdc); } }
private void RenderBackbufferRect() { if (!Buffer.DirtyRectangle.IsEmpty) { IntPtr hDC = DC.GetHdc(); IntPtr hDCBuffer = Buffer.DC.GetHdc(); Win32Support.DrawBitmap(hDC, Buffer.DirtyRectangle, hDCBuffer, Buffer.DirtyRectangle, TernaryRasterOperations.SRCCOPY); DC.ReleaseHdc(hDC); Buffer.DC.ReleaseHdc(hDCBuffer); // dirty rectangle drawn, so clear it out for next cycle ((Backbuffer)Buffer).DirtyRectangle = new Rectangle(); } }
public string SaveToFile(string file) { Bitmap toSave = new Bitmap(_bmp); Graphics graphics = Graphics.FromImage(toSave); IntPtr graphicsDC = graphics.GetHdc(); Win32Support.DrawBitmap(graphicsDC, 0, 0, toSave.Width, toSave.Height, hDC, 0, 0, toSave.Width, toSave.Height, TernaryRasterOperations.SRCCOPY); graphics.ReleaseHdc(graphicsDC); toSave.Save(file); graphics.Dispose(); toSave.Dispose(); return(file); }
public void Erase(IList <Rectangle> areas) { if (areas.Count == 0) { return; } IntPtr hDC = dc.GetHdc(); foreach (Rectangle area in areas) { Rectangle pxlRange = Rectangle.Intersect(area, range); Win32Support.DrawBitmap(hDC, pxlRange, hDC, pxlRange, TernaryRasterOperations.BLACKNESS); AddToDirtyRectangle(pxlRange); } dc.ReleaseHdc(hDC); }
private void AFCPanel_Resize(object sender, EventArgs e) { if (AFCPanel.Width == 0 || AFCPanel.Height == 0) { return; } Bitmap memBmp; memBmp = new Bitmap(AFCPanel.Width, AFCPanel.Height); Graphics clientDC = AFCPanel.CreateGraphics(); IntPtr hdc = clientDC.GetHdc(); IntPtr memdc = Win32Support.CreateCompatibleDC(hdc); Win32Support.SelectObject(memdc, memBmp.GetHbitmap()); memDC = Graphics.FromHdc(memdc); clientDC.ReleaseHdc(hdc); UpdateUI(); }
private void DrawTile(Tile tile, ref IntPtr hDC) { Rectangle tileLoc = tile.DrawLocation; // redraw each "refresh area" foreach (Rectangle refreshRect in tile.DrawLocationRefresh) { // clip the DrawLocationRefresh to Backbuffer if necessary Rectangle tempRefreshLoc = Rectangle.Intersect(refreshRect, range); // if the Tile is outside the range, has no Tilesheet, or is not visible, return without blitting if ((tempRefreshLoc.IsEmpty) || (tile.CurrentFrame.Tilesheet == null) || (tile.Visible == false)) { return; } // check if source Frame needs to be resized ResizedFrame resizedFrame = null; if (tileLoc.Size != tile.CurrentFrame.Tilesheet.TileSize) { resizedFrame = ResizedFrame.GetResizedFrame(tile.CurrentFrame, tileLoc.Size); } // get source refresh range, hDC, and related mask hdc Rectangle _srcRefreshRange; IntPtr _srcHDCMask; IntPtr _srcHDC; if (resizedFrame == null) { // get the source Rectangle being rendered and Graphics / DC handles from the Tilesheet object _srcRefreshRange = tile.CurrentFrame.Tilesheet.GetSourceRange(tile.CurrentFrame.XTile, tile.CurrentFrame.YTile); _srcHDC = tile.CurrentFrame.Tilesheet.hDC; if (tile.CurrentFrame.Tilesheet.Mask != null) { _srcHDCMask = tile.CurrentFrame.Tilesheet.Mask.hDC; } else { _srcHDCMask = default(IntPtr); } } else { // get the source Rectangle being rendered and Graphics / DC handles from the ResizedFrame object _srcRefreshRange = new Rectangle(new Point(0, 0), resizedFrame.RenderSize); _srcHDCMask = resizedFrame.hDCMask; _srcHDC = resizedFrame.hDC; } // if only refreshing part of the Tile... if (tileLoc.Size != tempRefreshLoc.Size) { // capture just the section of the source Tilesheet that needs to be refreshed on Backbuffer _srcRefreshRange = GetSourceBmpRangeForRefresh(_srcRefreshRange, tempRefreshLoc, tileLoc); } // if the Tilesheet has a mask... if (tile.CurrentFrame.Tilesheet.Mask != null) { // AND the mask Win32Support.DrawBitmap(hDC, tempRefreshLoc, _srcHDCMask, _srcRefreshRange, TernaryRasterOperations.SRCAND); // PAINT the primary Win32Support.DrawBitmap(hDC, tempRefreshLoc, _srcHDC, _srcRefreshRange, TernaryRasterOperations.SRCPAINT); } else { // use the specified Tile.RasterOp Win32Support.DrawBitmap(hDC, tempRefreshLoc, _srcHDC, _srcRefreshRange, tile.RasterOp); } } }