From 76ca7ccf3519c512ef987c9ffac015f42b7b8f22 Mon Sep 17 00:00:00 2001 From: Anton Mukhin Date: Mon, 2 Jun 2025 23:37:22 +0300 Subject: [PATCH] TODO feature: Middle mouse - drag the canvas --- McBitFont/FontTester.Designer.cs | 26 +++++++++++----------- McBitFont/Form1.Designer.cs | 7 +++++- McBitFont/Form1.cs | 37 ++++++++++++++++++++++++++++++++ TODO.txt | 2 +- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/McBitFont/FontTester.Designer.cs b/McBitFont/FontTester.Designer.cs index 3a0e37c..355ee76 100644 --- a/McBitFont/FontTester.Designer.cs +++ b/McBitFont/FontTester.Designer.cs @@ -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); diff --git a/McBitFont/Form1.Designer.cs b/McBitFont/Form1.Designer.cs index ffd5494..0427c47 100644 --- a/McBitFont/Form1.Designer.cs +++ b/McBitFont/Form1.Designer.cs @@ -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; diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index 45fa49a..2114a0c 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -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) { diff --git a/TODO.txt b/TODO.txt index f3aaef1..d1571b3 100644 --- a/TODO.txt +++ b/TODO.txt @@ -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