2013-04-15 02:14:14 +00:00
|
|
|
|
using System.Drawing;
|
2011-03-13 19:11:43 +00:00
|
|
|
|
using System.Windows.Forms;
|
2011-09-15 00:49:25 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Drawing.Imaging;
|
2011-03-13 19:11:43 +00:00
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2014-07-27 15:22:30 +00:00
|
|
|
|
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
2014-08-05 00:18:55 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System;
|
|
|
|
|
using BizHawk.Client.EmuHawk.CustomControls;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2011-03-13 19:11:43 +00:00
|
|
|
|
{
|
2013-04-15 02:14:14 +00:00
|
|
|
|
public sealed class NameTableViewer : Control
|
2011-06-10 08:10:16 +00:00
|
|
|
|
{
|
2013-04-15 02:14:14 +00:00
|
|
|
|
public Bitmap Nametables;
|
|
|
|
|
|
|
|
|
|
private readonly Size pSize;
|
2011-03-13 19:23:34 +00:00
|
|
|
|
|
2011-06-10 08:10:16 +00:00
|
|
|
|
public NameTableViewer()
|
|
|
|
|
{
|
|
|
|
|
pSize = new Size(512, 480);
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Nametables = new Bitmap(pSize.Width, pSize.Height);
|
2011-06-10 08:10:16 +00:00
|
|
|
|
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
|
|
|
SetStyle(ControlStyles.UserPaint, true);
|
2014-08-05 01:03:16 +00:00
|
|
|
|
SetStyle(ControlStyles.DoubleBuffer, false);
|
|
|
|
|
// SetStyle(ControlStyles.SupportsTransparentBackColor, false);
|
|
|
|
|
SetStyle(ControlStyles.Opaque, true);
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Size = new Size(256, 224);
|
2014-08-05 01:03:16 +00:00
|
|
|
|
//BackColor = Color.Transparent;
|
2014-08-05 00:18:55 +00:00
|
|
|
|
//Paint += NameTableViewer_Paint;
|
2011-06-10 08:10:16 +00:00
|
|
|
|
}
|
2011-03-13 19:11:43 +00:00
|
|
|
|
|
2011-06-10 08:10:16 +00:00
|
|
|
|
public enum WhichNametable
|
|
|
|
|
{
|
2011-08-27 21:07:09 +00:00
|
|
|
|
NT_2000, NT_2400, NT_2800, NT_2C00, NT_ALL, TOPS, BOTTOMS
|
2011-06-10 08:10:16 +00:00
|
|
|
|
}
|
2011-03-13 19:11:43 +00:00
|
|
|
|
|
2011-06-10 08:10:16 +00:00
|
|
|
|
public WhichNametable Which = WhichNametable.NT_ALL;
|
|
|
|
|
|
2014-08-05 01:03:16 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnPaintBackground(PaintEventArgs pevent)
|
2014-08-05 00:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
2014-08-05 01:03:16 +00:00
|
|
|
|
}
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var font = this.Font;
|
2014-08-05 00:18:55 +00:00
|
|
|
|
|
2014-08-05 01:03:16 +00:00
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(128);
|
|
|
|
|
Random r = new Random((int)DateTime.Now.Ticks);
|
|
|
|
|
for (int i = 0; i < 64; i++)
|
2014-08-05 00:18:55 +00:00
|
|
|
|
{
|
2014-08-05 01:03:16 +00:00
|
|
|
|
sb.Append((char)r.Next('a', 'z'));
|
|
|
|
|
}
|
|
|
|
|
string junk = sb.ToString();
|
|
|
|
|
|
2014-08-05 00:18:55 +00:00
|
|
|
|
|
2014-08-05 01:03:16 +00:00
|
|
|
|
using (var ntr = new NativeTextRenderer(this))
|
|
|
|
|
{
|
|
|
|
|
ntr.PrepDrawString(junk, font, Color.Black, new Point(0, 0));
|
|
|
|
|
ntr.DrawRectangle(0, 0, ClientRectangle.Right, ClientRectangle.Bottom);
|
|
|
|
|
for (int y = 0; y < 16; y++)
|
|
|
|
|
{
|
|
|
|
|
ntr.DrawString(junk, font, Color.Black, new Point(15, y * 30));
|
|
|
|
|
//e.Graphics.DrawString(sb.ToString(), this.Font, Brushes.Black, new Point(15, y * 30));
|
|
|
|
|
}
|
2014-08-05 00:18:55 +00:00
|
|
|
|
}
|
2014-08-05 01:03:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//e.Graphics.FillRectangle(Brushes.White, ClientRectangle);
|
|
|
|
|
//for (int y = 0; y < 16; y++)
|
|
|
|
|
//{
|
|
|
|
|
// e.Graphics.DrawString(junk, font, Brushes.Black, new Point(15, y * 30));
|
|
|
|
|
//}
|
|
|
|
|
|
2014-08-05 00:18:55 +00:00
|
|
|
|
//base.OnPaint(e);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-10 08:10:16 +00:00
|
|
|
|
private void NameTableViewer_Paint(object sender, PaintEventArgs e)
|
|
|
|
|
{
|
2011-08-29 01:09:16 +00:00
|
|
|
|
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
|
|
|
|
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
|
|
|
|
switch (Which)
|
|
|
|
|
{
|
|
|
|
|
case WhichNametable.NT_ALL:
|
2013-04-15 02:14:14 +00:00
|
|
|
|
e.Graphics.DrawImageUnscaled(Nametables, 0, 0);
|
2011-08-29 01:09:16 +00:00
|
|
|
|
break;
|
|
|
|
|
case WhichNametable.NT_2000:
|
2013-04-15 02:14:14 +00:00
|
|
|
|
e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 480), 0, 0, 256, 240, GraphicsUnit.Pixel);
|
2011-08-29 01:09:16 +00:00
|
|
|
|
break;
|
|
|
|
|
case WhichNametable.NT_2400:
|
2013-04-15 02:14:14 +00:00
|
|
|
|
e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 480), 256, 0, 256, 240, GraphicsUnit.Pixel);
|
2011-08-29 01:09:16 +00:00
|
|
|
|
break;
|
|
|
|
|
case WhichNametable.NT_2800:
|
2013-04-15 02:14:14 +00:00
|
|
|
|
e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 480), 0, 240, 256, 240, GraphicsUnit.Pixel);
|
2011-08-29 01:09:16 +00:00
|
|
|
|
break;
|
|
|
|
|
case WhichNametable.NT_2C00:
|
2013-04-15 02:14:14 +00:00
|
|
|
|
e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 480), 256, 240, 256, 240, GraphicsUnit.Pixel);
|
2011-08-29 01:09:16 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
//adelikat: Meh, just in case we might want these, someone requested it but I can't remember the justification so I didn't do the UI part
|
|
|
|
|
case WhichNametable.TOPS:
|
2013-04-15 02:14:14 +00:00
|
|
|
|
e.Graphics.DrawImage(Nametables, new Rectangle(0, 0, 512, 240), 0, 0, 512, 240, GraphicsUnit.Pixel);
|
2011-08-29 01:09:16 +00:00
|
|
|
|
break;
|
|
|
|
|
case WhichNametable.BOTTOMS:
|
2013-04-15 02:14:14 +00:00
|
|
|
|
e.Graphics.DrawImage(Nametables, new Rectangle(0, 240, 512, 240), 0, 240, 512, 240, GraphicsUnit.Pixel);
|
2011-08-29 01:09:16 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-10 08:10:16 +00:00
|
|
|
|
}
|
2011-09-15 00:49:25 +00:00
|
|
|
|
|
|
|
|
|
public void Screenshot()
|
|
|
|
|
{
|
2013-04-15 02:14:14 +00:00
|
|
|
|
var sfd = new SaveFileDialog
|
|
|
|
|
{
|
|
|
|
|
FileName = PathManager.FilesystemSafeName(Global.Game) + "-Nametables",
|
2013-08-11 21:48:17 +00:00
|
|
|
|
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries["NES", "Screenshots"].Path, "NES"),
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Filter = "PNG (*.png)|*.png|Bitmap (*.bmp)|*.bmp|All Files|*.*",
|
|
|
|
|
RestoreDirectory = true
|
|
|
|
|
};
|
2011-09-15 00:49:25 +00:00
|
|
|
|
|
2013-11-28 22:39:00 +00:00
|
|
|
|
var result = sfd.ShowHawkDialog();
|
2011-09-15 00:49:25 +00:00
|
|
|
|
if (result != DialogResult.OK)
|
2013-04-15 02:14:14 +00:00
|
|
|
|
{
|
2011-09-15 00:49:25 +00:00
|
|
|
|
return;
|
2013-04-15 02:14:14 +00:00
|
|
|
|
}
|
2011-09-15 00:49:25 +00:00
|
|
|
|
|
|
|
|
|
var file = new FileInfo(sfd.FileName);
|
2012-03-25 08:52:52 +00:00
|
|
|
|
using (Bitmap b = new Bitmap(Width, Height))
|
2011-09-15 00:49:25 +00:00
|
|
|
|
{
|
2012-03-25 08:52:52 +00:00
|
|
|
|
Rectangle rect = new Rectangle(new Point(0, 0), Size);
|
|
|
|
|
DrawToBitmap(b, rect);
|
2011-09-15 00:49:25 +00:00
|
|
|
|
|
2012-03-25 08:52:52 +00:00
|
|
|
|
ImageFormat i;
|
|
|
|
|
string extension = file.Extension.ToUpper();
|
|
|
|
|
switch (extension)
|
|
|
|
|
{
|
|
|
|
|
default:
|
|
|
|
|
case ".PNG":
|
|
|
|
|
i = ImageFormat.Png;
|
|
|
|
|
break;
|
|
|
|
|
case ".BMP":
|
|
|
|
|
i = ImageFormat.Bmp;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b.Save(file.FullName, i);
|
|
|
|
|
}
|
2011-09-15 00:49:25 +00:00
|
|
|
|
}
|
2012-03-09 19:07:16 +00:00
|
|
|
|
|
|
|
|
|
public void ScreenshotToClipboard()
|
|
|
|
|
{
|
2012-03-25 08:52:52 +00:00
|
|
|
|
using(var b = new Bitmap(Width, Height))
|
2012-03-09 19:07:16 +00:00
|
|
|
|
{
|
2012-03-25 08:52:52 +00:00
|
|
|
|
Rectangle rect = new Rectangle(new Point(0, 0), Size);
|
|
|
|
|
DrawToBitmap(b, rect);
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Clipboard.SetImage(b);
|
2012-03-09 19:07:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-10 08:10:16 +00:00
|
|
|
|
}
|
2011-03-13 19:11:43 +00:00
|
|
|
|
}
|