2015-02-24 20:10:47 -08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
2017-01-07 23:54:09 -08:00
|
|
|
|
using PKHeX.Core;
|
2021-11-27 15:48:08 -08:00
|
|
|
|
using PKHeX.Drawing.Misc;
|
2018-04-06 21:23:09 -07:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
|
|
|
|
|
2017-01-07 23:54:09 -08:00
|
|
|
|
namespace PKHeX.WinForms
|
2015-02-24 20:10:47 -08:00
|
|
|
|
{
|
|
|
|
|
public partial class QR : Form
|
|
|
|
|
{
|
2020-10-18 11:02:39 -07:00
|
|
|
|
private readonly PKM? pkm;
|
2016-11-28 23:02:25 -08:00
|
|
|
|
private readonly Image icon;
|
|
|
|
|
private Image qr;
|
2016-11-16 19:47:41 -08:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private readonly string[] Lines;
|
2020-10-18 11:02:39 -07:00
|
|
|
|
private string extraText = string.Empty;
|
2016-11-16 19:47:41 -08:00
|
|
|
|
|
2019-09-29 09:47:06 -07:00
|
|
|
|
public QR(Image qr, Image icon, params string[] lines)
|
2015-02-25 23:12:38 -08:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-09-29 09:47:06 -07:00
|
|
|
|
this.qr = qr;
|
|
|
|
|
this.icon = icon;
|
|
|
|
|
Lines = lines;
|
2019-12-23 20:16:34 -08:00
|
|
|
|
splitContainer1.Panel1Collapsed = true;
|
2019-09-29 09:47:06 -07:00
|
|
|
|
RefreshImage();
|
2019-12-23 20:16:34 -08:00
|
|
|
|
ResizeWindow();
|
2019-09-29 09:47:06 -07:00
|
|
|
|
}
|
2016-11-16 19:47:41 -08:00
|
|
|
|
|
2019-09-29 09:47:06 -07:00
|
|
|
|
public QR(Image qr, Image icon, PKM pk, params string[] lines)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-11-16 19:47:41 -08:00
|
|
|
|
this.qr = qr;
|
|
|
|
|
this.icon = icon;
|
2017-06-17 18:37:19 -07:00
|
|
|
|
Lines = lines;
|
2016-11-16 19:47:41 -08:00
|
|
|
|
|
2019-09-29 09:47:06 -07:00
|
|
|
|
pkm = pk;
|
|
|
|
|
// Layer on Text
|
2019-12-23 20:16:34 -08:00
|
|
|
|
if (pkm is PK7 pk7)
|
|
|
|
|
this.qr = ReloadQRData(pk7);
|
|
|
|
|
else
|
|
|
|
|
splitContainer1.Panel1Collapsed = true;
|
|
|
|
|
|
2019-09-29 09:47:06 -07:00
|
|
|
|
RefreshImage();
|
2019-12-23 20:16:34 -08:00
|
|
|
|
ResizeWindow();
|
|
|
|
|
splitContainer1.SplitterDistance = 34;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResizeWindow()
|
|
|
|
|
{
|
|
|
|
|
var img = PB_QR.Image;
|
|
|
|
|
splitContainer1.Height = splitContainer1.Panel1.Height + img.Height;
|
|
|
|
|
splitContainer1.Width = img.Width;
|
2015-02-24 20:42:05 -08:00
|
|
|
|
}
|
2018-05-12 08:13:39 -07:00
|
|
|
|
|
2019-12-23 20:16:34 -08:00
|
|
|
|
private Image ReloadQRData(PK7 pk7)
|
2016-06-19 21:22:43 -07:00
|
|
|
|
{
|
2019-09-29 09:47:06 -07:00
|
|
|
|
var box = (int)NUD_Box.Value - 1;
|
|
|
|
|
var slot = (int)NUD_Slot.Value - 1;
|
|
|
|
|
var copies = (int)NUD_Copies.Value;
|
|
|
|
|
extraText = $" (Box {box + 1}, Slot {slot + 1}, {copies} cop{(copies > 1 ? "ies" : "y")})";
|
2019-12-23 20:16:34 -08:00
|
|
|
|
return QREncode.GenerateQRCode7(pk7, box, slot, copies);
|
2017-08-13 00:21:42 -07:00
|
|
|
|
}
|
2018-07-21 19:20:11 -07:00
|
|
|
|
|
2019-09-29 09:47:06 -07:00
|
|
|
|
private void RefreshImage()
|
2017-08-13 00:21:42 -07:00
|
|
|
|
{
|
2019-09-29 09:47:06 -07:00
|
|
|
|
SuspendLayout();
|
|
|
|
|
ResumeLayout();
|
2019-10-26 23:14:00 -07:00
|
|
|
|
Font font = !Main.Unicode ? Font : FontUtil.GetPKXFont(8.25f);
|
2019-12-23 20:16:34 -08:00
|
|
|
|
var img = QRImageUtil.GetQRImageExtended(font, qr, icon, Math.Max(qr.Width, 370), qr.Height + 50, Lines, extraText);
|
|
|
|
|
PB_QR.Image = img;
|
2016-06-19 21:22:43 -07:00
|
|
|
|
}
|
2017-08-13 00:21:42 -07:00
|
|
|
|
|
2019-09-29 09:47:06 -07:00
|
|
|
|
private void PB_QR_Click(object sender, EventArgs e)
|
2016-06-19 21:22:43 -07:00
|
|
|
|
{
|
2019-10-04 20:10:50 -07:00
|
|
|
|
if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgQRClipboardImage))
|
2019-09-29 09:47:06 -07:00
|
|
|
|
return;
|
2019-12-23 20:16:34 -08:00
|
|
|
|
try { Clipboard.SetImage(PB_QR.Image); }
|
2020-09-18 22:11:13 -07:00
|
|
|
|
// Clipboard can be locked periodically, just notify on failure.
|
2019-09-29 09:47:06 -07:00
|
|
|
|
catch { WinFormsUtil.Alert(MsgQRClipboardFail); }
|
2016-06-19 21:22:43 -07:00
|
|
|
|
}
|
2016-11-16 19:47:41 -08:00
|
|
|
|
|
2017-06-17 18:37:19 -07:00
|
|
|
|
private void UpdateBoxSlotCopies(object sender, EventArgs e)
|
2016-11-16 19:47:41 -08:00
|
|
|
|
{
|
2020-12-22 21:24:41 -08:00
|
|
|
|
if (pkm is not PK7 pk7)
|
2016-11-16 19:47:41 -08:00
|
|
|
|
throw new ArgumentException("Can't update QR7 if pkm isn't a PK7!");
|
2019-12-23 20:16:34 -08:00
|
|
|
|
qr = ReloadQRData(pk7);
|
2016-11-16 19:47:41 -08:00
|
|
|
|
RefreshImage();
|
2017-01-11 17:55:42 -08:00
|
|
|
|
}
|
2015-02-24 20:10:47 -08:00
|
|
|
|
}
|
2017-05-15 17:07:07 -03:00
|
|
|
|
}
|