diff --git a/McBitFont/ChangeHistory.cs b/McBitFont/ChangeHistory.cs index 80b3b24..25b2dfa 100644 --- a/McBitFont/ChangeHistory.cs +++ b/McBitFont/ChangeHistory.cs @@ -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; diff --git a/McBitFont/FontTester.Designer.cs b/McBitFont/FontTester.Designer.cs index 4fc6680..3a0e37c 100644 --- a/McBitFont/FontTester.Designer.cs +++ b/McBitFont/FontTester.Designer.cs @@ -35,6 +35,7 @@ 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(); ((System.ComponentModel.ISupportInitialize)nudSpace).BeginInit(); SuspendLayout(); // @@ -151,11 +152,27 @@ chkBaseline.UseVisualStyleBackColor = true; chkBaseline.CheckedChanged += Scrolling; // + // 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; + // // FontTester // 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; } } \ No newline at end of file diff --git a/McBitFont/FontTester.cs b/McBitFont/FontTester.cs index e30cf02..073a192 100644 --- a/McBitFont/FontTester.cs +++ b/McBitFont/FontTester.cs @@ -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 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); + } } diff --git a/TODO.txt b/TODO.txt index 72f831f..f3aaef1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -5,7 +5,7 @@ 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 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" \ No newline at end of file