|
|
ebcc4f |
using System;
|
|
|
ebcc4f |
using System.Drawing;
|
|
|
ebcc4f |
using System.Drawing.Imaging;
|
|
|
ebcc4f |
using System.Collections.Generic;
|
|
|
ebcc4f |
|
|
|
ebcc4f |
namespace Assistance {
|
|
|
ebcc4f |
public class Canvas {
|
|
|
b1ff53 |
public static readonly int initialSize = 100;
|
|
|
b1ff53 |
public static readonly double incrementScale = 1.2;
|
|
|
b1ff53 |
|
|
|
b1ff53 |
private System.Drawing.Point offset = new System.Drawing.Point(-initialSize/2, -initialSize/2);
|
|
|
b1ff53 |
private Bitmap bitmap = new Bitmap(initialSize, initialSize);
|
|
|
b1ff53 |
|
|
|
b1ff53 |
public void draw(Graphics g) {
|
|
|
b1ff53 |
g.DrawImageUnscaled(bitmap, offset);
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
b1ff53 |
public void expand(Rectangle rect) {
|
|
|
b1ff53 |
System.Drawing.Point lt = offset;
|
|
|
b1ff53 |
System.Drawing.Point rb = lt + bitmap.Size;
|
|
|
b1ff53 |
System.Drawing.Rectangle recti = rect.toInt();
|
|
|
b1ff53 |
|
|
|
b1ff53 |
int incX = (int)Math.Ceiling(bitmap.Width*incrementScale);
|
|
|
b1ff53 |
int incY = (int)Math.Ceiling(bitmap.Height*incrementScale);
|
|
|
b1ff53 |
|
|
|
b1ff53 |
if (recti.Left < lt.X) lt.X = recti.Left - incX;
|
|
|
b1ff53 |
if (recti.Top < lt.Y) lt.Y = recti.Top - incY;
|
|
|
b1ff53 |
if (recti.Right > rb.X) rb.X = recti.Right + incX;
|
|
|
b1ff53 |
if (recti.Bottom > rb.Y) rb.Y = recti.Bottom + incY;
|
|
|
b1ff53 |
|
|
|
b1ff53 |
Size size = new Size(rb.X - lt.X, rb.Y - lt.Y);
|
|
|
b1ff53 |
if (lt != offset || size != bitmap.Size) {
|
|
|
b1ff53 |
Bitmap newBitmap = new Bitmap(size.Width, size.Height);
|
|
|
b1ff53 |
Graphics g = Graphics.FromImage(newBitmap);
|
|
|
b1ff53 |
g.DrawImageUnscaled(bitmap, new System.Drawing.Point(offset.X - lt.X, offset.Y - lt.Y));
|
|
|
b1ff53 |
g.Flush();
|
|
|
b1ff53 |
|
|
|
b1ff53 |
offset = lt;
|
|
|
b1ff53 |
bitmap = newBitmap;
|
|
|
b1ff53 |
}
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
b1ff53 |
private Graphics getGraphics() {
|
|
|
b1ff53 |
Graphics g = Graphics.FromImage(bitmap);
|
|
|
b1ff53 |
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
|
|
b1ff53 |
g.TranslateTransform(-offset.X, -offset.Y);
|
|
|
b1ff53 |
return g;
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
b1ff53 |
public void paintTrack(Track track) {
|
|
|
b1ff53 |
expand(track.getBounds());
|
|
|
b1ff53 |
Graphics g = getGraphics();
|
|
|
b1ff53 |
track.draw(g);
|
|
|
b1ff53 |
g.Flush();
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|