2019-04-21 17:34:27 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Controls;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger.PpuViewer
|
|
|
|
|
{
|
|
|
|
|
public partial class ctrlImagePanel : BaseControl
|
|
|
|
|
{
|
|
|
|
|
private int _scale = 1;
|
|
|
|
|
private Size _imageSize;
|
|
|
|
|
|
|
|
|
|
public Rectangle Selection { get { return ctrlImageViewer.Selection; } set { ctrlImageViewer.Selection = value; } }
|
2019-04-25 19:49:15 -04:00
|
|
|
|
public int SelectionWrapPosition { get { return ctrlImageViewer.SelectionWrapPosition; } set { ctrlImageViewer.SelectionWrapPosition = value; } }
|
|
|
|
|
|
2019-04-21 17:34:27 -04:00
|
|
|
|
public Size ImageSize { get { return _imageSize; } set { _imageSize = value; UpdateMapSize(); } }
|
|
|
|
|
public Image Image { get { return ctrlImageViewer.Image; } set { ctrlImageViewer.Image = value; } }
|
2019-04-25 19:49:15 -04:00
|
|
|
|
public int ImageScale { get { return _scale; } set { _scale = value; UpdateMapSize(); } }
|
2019-05-02 20:22:29 -04:00
|
|
|
|
public Point ScrollOffsets { get { return new Point(ctrlPanel.HorizontalScroll.Value, ctrlPanel.VerticalScroll.Value); } }
|
2019-04-21 17:34:27 -04:00
|
|
|
|
|
2019-05-02 20:22:29 -04:00
|
|
|
|
public new event EventHandler MouseLeave { add { ctrlImageViewer.MouseLeave += value; } remove { ctrlImageViewer.MouseLeave -= value; } }
|
|
|
|
|
public new event MouseEventHandler MouseMove { add { ctrlImageViewer.MouseMove += value; } remove { ctrlImageViewer.MouseMove -= value; } }
|
2019-04-21 17:34:27 -04:00
|
|
|
|
public new event MouseEventHandler MouseClick { add { ctrlImageViewer.MouseClick += value; } remove { ctrlImageViewer.MouseClick -= value; } }
|
|
|
|
|
|
|
|
|
|
public ctrlImagePanel()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
if(DesignMode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctrlPanel.OnZoom += (scaleDelta) => {
|
|
|
|
|
double hori = (double)ctrlPanel.HorizontalScroll.Value / _scale + (double)ctrlPanel.Width / 2 / _scale;
|
|
|
|
|
double vert = (double)ctrlPanel.VerticalScroll.Value / _scale + (double)ctrlPanel.Height / 2 / _scale;
|
|
|
|
|
|
|
|
|
|
_scale = Math.Min(16, Math.Max(1, _scale + scaleDelta));
|
|
|
|
|
UpdateMapSize();
|
|
|
|
|
|
2019-05-05 00:36:15 -04:00
|
|
|
|
int horizontalScroll = Math.Max(0, Math.Min((int)(hori * _scale) - ctrlPanel.Width / 2, ctrlPanel.HorizontalScroll.Maximum));
|
|
|
|
|
int verticalScroll = Math.Max(0, Math.Min((int)(vert * _scale) - ctrlPanel.Height / 2, ctrlPanel.VerticalScroll.Maximum));
|
|
|
|
|
|
|
|
|
|
//Set the values twice to avoid a scroll position bug
|
|
|
|
|
ctrlPanel.HorizontalScroll.Value = horizontalScroll;
|
|
|
|
|
ctrlPanel.HorizontalScroll.Value = horizontalScroll;
|
|
|
|
|
ctrlPanel.VerticalScroll.Value = verticalScroll;
|
|
|
|
|
ctrlPanel.VerticalScroll.Value = verticalScroll;
|
2019-04-21 17:34:27 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateMapSize()
|
|
|
|
|
{
|
|
|
|
|
ctrlImageViewer.Width = ImageSize.Width * _scale;
|
|
|
|
|
ctrlImageViewer.Height = ImageSize.Height * _scale;
|
|
|
|
|
ctrlImageViewer.ImageScale = _scale;
|
|
|
|
|
ctrlImageViewer.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInvalidated(InvalidateEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnInvalidated(e);
|
|
|
|
|
ctrlImageViewer.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ZoomIn()
|
|
|
|
|
{
|
|
|
|
|
_scale = Math.Min(16, _scale + 1);
|
|
|
|
|
UpdateMapSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ZoomOut()
|
|
|
|
|
{
|
|
|
|
|
_scale = Math.Max(1, _scale - 1);
|
|
|
|
|
UpdateMapSize();
|
|
|
|
|
}
|
2019-05-05 00:36:15 -04:00
|
|
|
|
|
|
|
|
|
public void ScrollTo(int scrollPos)
|
|
|
|
|
{
|
|
|
|
|
ctrlPanel.VerticalScroll.Value = scrollPos;
|
|
|
|
|
ctrlPanel.VerticalScroll.Value = scrollPos;
|
|
|
|
|
|
|
|
|
|
ctrlPanel.HorizontalScroll.Value = 0;
|
|
|
|
|
ctrlPanel.HorizontalScroll.Value = 0;
|
|
|
|
|
}
|
2019-04-21 17:34:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|