2012-11-05 01:34:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient.GBtools
|
|
|
|
|
{
|
|
|
|
|
public partial class BmpView : Control
|
|
|
|
|
{
|
2012-11-05 14:37:55 +00:00
|
|
|
|
public Bitmap bmp { get; private set; }
|
|
|
|
|
bool scaled;
|
2012-11-05 01:34:11 +00:00
|
|
|
|
|
|
|
|
|
public BmpView()
|
|
|
|
|
{
|
|
|
|
|
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.UserPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.DoubleBuffer, true);
|
|
|
|
|
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
|
|
|
|
|
SetStyle(ControlStyles.Opaque, true);
|
|
|
|
|
this.BackColor = Color.Transparent;
|
|
|
|
|
this.Paint += new PaintEventHandler(BmpView_Paint);
|
2012-11-05 14:37:55 +00:00
|
|
|
|
ChangeBitmapSize(1, 1);
|
2012-11-05 01:34:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BmpView_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
{
|
2012-11-05 14:37:55 +00:00
|
|
|
|
if (scaled)
|
2012-11-05 01:34:11 +00:00
|
|
|
|
{
|
|
|
|
|
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
|
|
|
|
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
2012-11-05 14:37:55 +00:00
|
|
|
|
e.Graphics.DrawImage(bmp, 0, 0, Width, Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-11-05 01:34:11 +00:00
|
|
|
|
e.Graphics.DrawImageUnscaled(bmp, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-05 14:37:55 +00:00
|
|
|
|
public void ChangeBitmapSize(Size s)
|
|
|
|
|
{
|
|
|
|
|
ChangeBitmapSize(s.Width, s.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeBitmapSize(int w, int h)
|
2012-11-05 01:34:11 +00:00
|
|
|
|
{
|
|
|
|
|
if (bmp != null)
|
|
|
|
|
bmp.Dispose();
|
2012-11-05 14:37:55 +00:00
|
|
|
|
bmp = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
|
|
|
|
scaled = !(w == Width && h == Height);
|
2012-11-05 01:34:11 +00:00
|
|
|
|
}
|
2012-11-05 13:48:19 +00:00
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
var lockdata = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
|
2012-11-05 14:37:55 +00:00
|
|
|
|
//Win32.ZeroMemory(lockdata.Scan0, (uint)(lockdata.Height * lockdata.Stride));
|
|
|
|
|
Win32.MemSet(lockdata.Scan0, 0xff, (uint)(lockdata.Height * lockdata.Stride));
|
2012-11-05 13:48:19 +00:00
|
|
|
|
bmp.UnlockBits(lockdata);
|
|
|
|
|
Refresh();
|
|
|
|
|
}
|
2012-11-05 14:37:55 +00:00
|
|
|
|
|
|
|
|
|
// kill unused props
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public override Color BackColor { get { return base.BackColor; } set { base.BackColor = value; } }
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public override string Text { get { return base.Text; } set { base.Text = value; } }
|
2012-11-05 01:34:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|