[2.0] Detecting what area can be painted
I am using this.Invalidate(new Rectangle(x, y, width, height));
If I have my paint event, how can I detect what is the area to be drawn into?
Code:
Code:
private void Form1_Paint(object sender, PaintEventArgs e)
{
//the if is what I am trying to do to detect if I am drawing into the whole screen... (like just calling me.Refresh())
if (e.Graphics.ClipBounds.X == this.Bounds.Width && e.Graphics.ClipBounds.Y == this.Bounds.Height)
{
for (int i = 0; i < formTilesX; i++)
{
for (int k = 0; k < formTilesY; k++)
{
if ((k * gridWidth) < (((playerX + formTilesX) * gridWidth) + gridWidth) && (i * gridHeight) < (((playerY + formTilesY) * gridHeight)) + gridHeight)
{
Bitmap bmp = new Bitmap(images[currentGrid[i, k]]);
e.Graphics.DrawImage(bmp, new Point(k * gridWidth, i * gridHeight));
bmp.Dispose();
bmp = null;
}
}
}
}
Bitmap playerBmp = new Bitmap(Resources.fighter);
e.Graphics.DrawImage(playerBmp, new Point(playerX * gridWidth, playerY * gridHeight));
playerBmp.Dispose();
playerBmp = null;
//HighlightTile(e);
}
Any idea's?
Thanks
Re: [2.0] Detecting what area can be painted
You don't. You just draw everything. The system then decides what part of that drawing will actually be painted to the screen based on what has been invalidated. It's not your logic that is time consuming. It's actually pushing the pixels to the screen that's the slow part, and the system is responsible for managing that.
Re: [2.0] Detecting what area can be painted
So the big for loop won't slow me down much?
well, Thanks