TODO feature: Middle mouse - drag the canvas

This commit is contained in:
2025-06-02 23:37:22 +03:00
parent 3c656b36a7
commit 76ca7ccf35
4 changed files with 57 additions and 15 deletions

View File

@@ -34,8 +34,8 @@
lblZoom = new System.Windows.Forms.Label();
cbZoom = new System.Windows.Forms.ComboBox();
toolTip1 = new System.Windows.Forms.ToolTip(components);
chkBaseline = new System.Windows.Forms.CheckBox();
btnCopy = new System.Windows.Forms.Button();
chkBaseline = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)nudSpace).BeginInit();
SuspendLayout();
//
@@ -99,7 +99,7 @@
vScroll.LargeChange = 25;
vScroll.Location = new System.Drawing.Point(251, 84);
vScroll.Name = "vScroll";
vScroll.Size = new System.Drawing.Size(21, 125);
vScroll.Size = new System.Drawing.Size(21, 104);
vScroll.TabIndex = 17;
vScroll.ValueChanged += Scrolling;
//
@@ -141,17 +141,6 @@
toolTip1.InitialDelay = 500;
toolTip1.ReshowDelay = 100;
//
// chkBaseline
//
chkBaseline.AutoSize = true;
chkBaseline.Location = new System.Drawing.Point(203, 36);
chkBaseline.Name = "chkBaseline";
chkBaseline.Size = new System.Drawing.Size(69, 19);
chkBaseline.TabIndex = 20;
chkBaseline.Text = "Baseline";
chkBaseline.UseVisualStyleBackColor = true;
chkBaseline.CheckedChanged += Scrolling;
//
// btnCopy
//
btnCopy.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
@@ -167,6 +156,17 @@
btnCopy.UseVisualStyleBackColor = true;
btnCopy.MouseClick += Copy_Click;
//
// chkBaseline
//
chkBaseline.AutoSize = true;
chkBaseline.Location = new System.Drawing.Point(203, 36);
chkBaseline.Name = "chkBaseline";
chkBaseline.Size = new System.Drawing.Size(69, 19);
chkBaseline.TabIndex = 20;
chkBaseline.Text = "Baseline";
chkBaseline.UseVisualStyleBackColor = true;
chkBaseline.CheckedChanged += Scrolling;
//
// FontTester
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);

View File

@@ -493,7 +493,10 @@
// hScroll
//
hScroll.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
hScroll.Enabled = false;
hScroll.LargeChange = 2;
hScroll.Location = new System.Drawing.Point(14, 609);
hScroll.Maximum = 1;
hScroll.Name = "hScroll";
hScroll.Size = new System.Drawing.Size(427, 21);
hScroll.TabIndex = 14;
@@ -502,8 +505,10 @@
// vScroll
//
vScroll.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
vScroll.LargeChange = 25;
vScroll.Enabled = false;
vScroll.LargeChange = 2;
vScroll.Location = new System.Drawing.Point(444, 31);
vScroll.Maximum = 1;
vScroll.Name = "vScroll";
vScroll.Size = new System.Drawing.Size(21, 575);
vScroll.TabIndex = 15;

View File

@@ -296,6 +296,7 @@ namespace McBitFont {
if (w <= dotPanel.Width) {
hScroll.Enabled = false;
hScroll.Value = 0;
vScroll.Maximum = 0;
} else {
hScroll.Maximum = w - dotPanel.Width + 12;
hScroll.Minimum = 0;
@@ -305,6 +306,7 @@ namespace McBitFont {
if (h <= dotPanel.Height) {
vScroll.Enabled = false;
vScroll.Value = 0;
vScroll.Maximum = 0;
} else {
vScroll.Maximum = h - dotPanel.Height + 12;
vScroll.Minimum = 0;
@@ -416,10 +418,45 @@ namespace McBitFont {
private bool mouseDown = false;
private bool fChanged = false;
private bool mouseDownMiddle = false;
private int mouseX, mouseY;
private void dotPanel_MouseMove(object sender, MouseEventArgs e) {
var rectSel = chkRectSelect.Checked;
bool rectSelUpdated = false;
// Drag with middle mouse button
if (vScroll.Enabled || hScroll.Enabled) {
if (mouseDownMiddle) {
var dY = mouseY - e.Y <= -cellSize - gap || mouseY - e.Y >= cellSize + gap;
var dX = mouseX - e.X <= -cellSize - gap || mouseX - e.X >= cellSize + gap;
int newY = vScroll.Value;
int newX = hScroll.Value;
if (dX) {
newX += (mouseX - e.X);
if (newX < hScroll.Minimum) newX = hScroll.Minimum;
if (newX > hScroll.Maximum) newX = hScroll.Maximum;
mouseX = e.X;
hScroll.Value = newX;
}
if (dY) {
newY += (mouseY - e.Y);
if (newY < vScroll.Minimum) newY = vScroll.Minimum;
if (newY > vScroll.Maximum) newY = vScroll.Maximum;
mouseY = e.Y;
vScroll.Value = newY;
}
}
if (!mouseDownMiddle && e.Button == MouseButtons.Middle) {
mouseDownMiddle = true;
mouseX = e.X;
mouseY = e.Y;
}
if (mouseDownMiddle && e.Button == MouseButtons.None) {
mouseDownMiddle = false;
}
}
// Moving baseline
Rectangle rect1, rect2;
if (set_base) {

View File

@@ -3,7 +3,7 @@ Application:
Functionality:
- Middle mouse - drag the canvas
V Middle mouse - drag the canvas
- Straight line painting
V A button to Copy from Test font dialog to then paste into another frame