Fix cropping and panning at the same time

Hopefully increase performance
- not updating backgroundBrush when panning
- move backgroundBrush instead
- draw backgroundBrush ony in ImageRectangle
- clear only when ImageRectangle does not cover whole screen
This commit is contained in:
L1Q 2017-10-17 14:13:21 +03:00
parent 522b52a8f8
commit aeec1ad4ad
2 changed files with 26 additions and 28 deletions

View file

@ -185,24 +185,6 @@ public void Prepare(Image img)
}
}
internal void UpdateBackground()
{
using (Bitmap background = new Bitmap(ScreenRectangle0Based.Width, ScreenRectangle0Based.Height))
using (Graphics g = Graphics.FromImage(background))
{
g.Clear(Color.FromArgb(14, 14, 14));
using (Image checkers = ImageHelpers.DrawCheckers(ImageRectangle.Width, ImageRectangle.Height))
{
g.DrawImage(checkers, ImageRectangle);
}
g.DrawImage(Image, ImageRectangle);
backgroundBrush = new TextureBrush(background) { WrapMode = WrapMode.Clamp };
}
}
internal void InitBackground(Image img)
{
if (Image != null) Image.Dispose();
@ -221,8 +203,19 @@ internal void InitBackground(Image img)
}
ImageRectangle = new Rectangle(rect.X + rect.Width / 2 - Image.Width / 2, rect.Y + rect.Height / 2 - Image.Height / 2, Image.Width, Image.Height);
using (Bitmap background = new Bitmap(ScreenRectangle0Based.Width, ScreenRectangle0Based.Height))
using (Graphics g = Graphics.FromImage(background))
{
using (Image checkers = ImageHelpers.DrawCheckers(ImageRectangle.Width, ImageRectangle.Height))
{
g.DrawImage(checkers, ImageRectangle);
}
UpdateBackground();
g.DrawImage(Image, ImageRectangle);
backgroundBrush = new TextureBrush(background) { WrapMode = WrapMode.Clamp };
}
}
else if (Config.UseDimming)
{
@ -430,13 +423,9 @@ private new void Update()
if(ShapeManager.IsPanning)
{
ImageRectangle = ImageRectangle.LocationOffset(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
backgroundBrush.TranslateTransform(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
foreach(BaseShape shape in ShapeManager.Shapes)
{
shape.Move(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
}
UpdateBackground();
ShapeManager.MoveAll(InputManager.MouseVelocity);
}
borderDotPen.DashOffset = (float)timerStart.Elapsed.TotalSeconds * -15;
@ -455,9 +444,10 @@ protected override void OnPaint(PaintEventArgs e)
Graphics g = e.Graphics;
g.CompositingMode = CompositingMode.SourceCopy;
g.FillRectangle(backgroundBrush, ScreenRectangle0Based);
if (!ImageRectangle.Contains(ScreenRectangle0Based))
g.Clear(Color.FromArgb(14, 14, 14));
g.FillRectangle(backgroundBrush, ImageRectangle);
g.CompositingMode = CompositingMode.SourceOver;
Draw(g);
if (Config.ShowFPS)

View file

@ -729,7 +729,7 @@ private void EndRegionSelection()
private void StartPanning()
{
DeselectCurrentShape();
// DeselectCurrentShape();
IsPanning = true;
}
@ -1196,6 +1196,14 @@ private bool IsShapeTypeRegion(ShapeType shapeType)
return false;
}
public void MoveAll(Point offset)
{
foreach (BaseShape shape in Shapes)
{
shape.Move(offset.X, offset.Y);
}
}
private void UpdateNodes()
{
BaseShape shape = CurrentShape;