Merge branch 'dev' - v2.5

Changes:

Functionality:
- Middle mouse - drag the canvas
- Straight line painting (hold Shift / Ctrl)
- A button to Copy from Test font dialog to then paste into another frame

Bugs fixed:
- Nothing selected after removing a symbol. Potential error throw on "Apply"
This commit is contained in:
Anton Mukhin
2025-06-03 11:50:38 +03:00
9 changed files with 132 additions and 17 deletions

View File

@@ -61,7 +61,7 @@ namespace McBitFont {
public FrameMiniature? Canvas { get; set; } = canvas;
}
private static FrameMiniature CopyFrameSimple(FrameMiniature f) {
public static FrameMiniature CopyFrameSimple(FrameMiniature f) {
FrameMiniature newf = new(f.code, f.width, f.height);
Array.Copy(f.data, newf.data, f.data.Length);
return newf;

View File

@@ -34,6 +34,7 @@
lblZoom = new System.Windows.Forms.Label();
cbZoom = new System.Windows.Forms.ComboBox();
toolTip1 = new System.Windows.Forms.ToolTip(components);
btnCopy = new System.Windows.Forms.Button();
chkBaseline = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)nudSpace).BeginInit();
SuspendLayout();
@@ -98,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;
//
@@ -140,6 +141,21 @@
toolTip1.InitialDelay = 500;
toolTip1.ReshowDelay = 100;
//
// btnCopy
//
btnCopy.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
btnCopy.Image = Properties.Resources.Famfamfam_Silk_Page_copy_16;
btnCopy.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
btnCopy.Location = new System.Drawing.Point(110, 214);
btnCopy.Name = "btnCopy";
btnCopy.Size = new System.Drawing.Size(80, 30);
btnCopy.TabIndex = 21;
btnCopy.Text = " Copy";
btnCopy.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
toolTip1.SetToolTip(btnCopy, "Copy BitPixels you see to Clipboard");
btnCopy.UseVisualStyleBackColor = true;
btnCopy.MouseClick += Copy_Click;
//
// chkBaseline
//
chkBaseline.AutoSize = true;
@@ -155,7 +171,8 @@
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(284, 221);
ClientSize = new System.Drawing.Size(284, 251);
Controls.Add(btnCopy);
Controls.Add(chkBaseline);
Controls.Add(cbZoom);
Controls.Add(lblZoom);
@@ -168,13 +185,14 @@
Controls.Add(lblSpace);
MaximizeBox = false;
MinimizeBox = false;
MinimumSize = new System.Drawing.Size(260, 260);
MinimumSize = new System.Drawing.Size(300, 290);
Name = "FontTester";
ShowIcon = false;
ShowInTaskbar = false;
StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
Text = "Font Tester";
Load += FontTester_Load;
Resize += Form_Resize;
((System.ComponentModel.ISupportInitialize)nudSpace).EndInit();
ResumeLayout(false);
PerformLayout();
@@ -193,5 +211,6 @@
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.ComboBox cbZoom;
private System.Windows.Forms.CheckBox chkBaseline;
private System.Windows.Forms.Button btnCopy;
}
}

View File

@@ -1,4 +1,5 @@
using System;
using MessagePack;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -24,6 +25,8 @@ namespace McBitFont {
private int cellSize;
private int width;
private readonly DataFormats.Format clpbFormat = DataFormats.GetFormat("McBitFontFrame");
public FontTester(int codepage, int height, int baseline, List<MainForm.FrameMiniature> frames) {
InitializeComponent();
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
@@ -53,7 +56,7 @@ namespace McBitFont {
int space = (int)nudSpace.Value;
int index = 0;
for (int c = 0; c < encoded.Length; c++) {
// Check if we have suck symbol
// Check if we have such symbol
var f = frames.FindAll(x => x.code == encoded[c]);
if (f.Count == 1) {
// Draw the symbol
@@ -160,6 +163,42 @@ namespace McBitFont {
private void Scrolling(object sender, EventArgs e) {
dotPanel.Invalidate();
}
private void Form_Resize(object sender, EventArgs e) {
btnCopy.Left = this.Width / 2 - 40;
}
private void Copy_Click(object sender, MouseEventArgs e) {
if (encoded.Length < 1) {
MessageBox.Show("Nothing to copy! Type some symbols first.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Sycle through ecoded bytes of test text
int space = (int)nudSpace.Value;
int index = 0;
int i, j;
MainForm.FrameMiniature ff = new(0, width, frames[0].height);
for (int c = 0; c < encoded.Length; c++) {
// Check if we have such symbol
var f = frames.FindAll(x => x.code == encoded[c]);
if (f.Count == 1) {
// Draw the symbol
for (i = 0; i < f[0].width; i++) {
for (j = 0; j < f[0].height; j++) {
// Fill the frame with data
ff.data[index + i, j] = f[0].data[i, j];
}
}
index += (f[0].width > 0 ? f[0].width + space : 0);
} else {
index += 5 + space;
}
}
// Copy the frame we made into Clipboard
var bb = MessagePackSerializer.Serialize(ChangeHistory.CopyFrameSimple(ff));
DataObject clpbObj = new DataObject(clpbFormat.Name, bb);
Clipboard.SetDataObject(clpbObj, true);
}
}

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

@@ -59,7 +59,7 @@ namespace McBitFont {
public bool monospaced = false;
private bool modified = false;
private bool prjModified = false;
public const string version = "2.4";
public const string version = "2.5";
public string prjName = "Untitled";
public string prjFileName = "";
public int codepage = 1251;
@@ -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;
@@ -414,12 +416,48 @@ namespace McBitFont {
dotPanel.Refresh();
}
private bool mouseDown = false;
private bool fChanged = false;
private bool mouseDown = false; // Used in canvas history tracking and rectangle selection logics
private bool fChanged = false; // Used in canvas history (undo / redo) tracking
private bool mouseDownMiddle = false; // Used in middle mouse dragging logic
private int mouseX, mouseY; // To remember last mouse X and Y (used in middle mouse dragging logic)
private int lastX = 0, lastY = 0; // Used for drawing straight lines
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) {
@@ -514,6 +552,15 @@ namespace McBitFont {
return;
}
// Check for Shift / Ctrl keys for straight lines
if (ModifierKeys.HasFlag(Keys.Shift)) {
j = lastY;
} else if (ModifierKeys.HasFlag(Keys.Control)) {
i = lastX;
}
lastX = i;
lastY = j;
// Paint black / white
if (e.Button == MouseButtons.Left && !f.data[i, j]) {
f.data[i, j] = true;
@@ -988,8 +1035,11 @@ namespace McBitFont {
var sel = miniList.SelectedItems[0].ImageKey;
int code = Convert.ToInt32(miniList.SelectedItems[0].ImageKey);
FrameMiniature ff = frames.Find(x => x.code == code);
bool isLast = frames.Last().Equals(ff);
frames.Remove(ff);
miniList.SelectedItems[0].Remove();
miniList.Items[isLast ? miniList.Items.Count - 1 : 0].Selected = true;
}
private void prependSymbolToolStripMenuItem_Click(object sender, EventArgs e) {

View File

@@ -20,9 +20,9 @@
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<ApplicationIcon>icon_64.ico</ApplicationIcon>
<AssemblyVersion>2.4.0.0</AssemblyVersion>
<FileVersion>2.4.0.0</FileVersion>
<Version>$(VersionPrefix)2.4.0</Version>
<AssemblyVersion>2.5.0.0</AssemblyVersion>
<FileVersion>2.5.0.0</FileVersion>
<Version>$(VersionPrefix)2.5.0</Version>
<Copyright>Anton Mukhin</Copyright>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -20,6 +20,8 @@ Some basic hints on the interface:
- Mouse 1 to mark a pixel black
- Mouse 2 to mark a pixel white
- Drag the mouse holding a button to draw pixels
- Hold Shift to constrain painting horizontally
- Hold Ctrl to constrain painting vertically
- Mouse Scroll to scroll up and down
- Shift + scroll to scroll left and right
- Crtl + scroll to zoom

View File

@@ -3,9 +3,9 @@ Application:
Functionality:
- Middle mouse - drag the canvas
- Straight line painting
- A button to Copy from Test font dialog to then paste into another frame
V Middle mouse - drag the canvas
V Straight line painting (hold Shift / Ctrl)
V A button to Copy from Test font dialog to then paste into another frame
Bugs:
- Nothing selected after removing a symbol. Potential error throw on "Apply"
V Nothing selected after removing a symbol. Potential error throw on "Apply"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 12 KiB