diff --git a/McBitFont/App.config b/McBitFont/App.config index 56efbc7..7d84477 100644 --- a/McBitFont/App.config +++ b/McBitFont/App.config @@ -1,6 +1,14 @@ - + + + + + + + + + \ No newline at end of file diff --git a/McBitFont/Form1.Designer.cs b/McBitFont/Form1.Designer.cs index 44226b7..9a10dc0 100644 --- a/McBitFont/Form1.Designer.cs +++ b/McBitFont/Form1.Designer.cs @@ -34,6 +34,7 @@ this.cbZoom = new System.Windows.Forms.ComboBox(); this.label4 = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); + this.btnClear = new System.Windows.Forms.Button(); this.btnMirrorY = new System.Windows.Forms.Button(); this.btnMirrorX = new System.Windows.Forms.Button(); this.btnInvert = new System.Windows.Forms.Button(); @@ -52,6 +53,7 @@ this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveDEVToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -63,6 +65,7 @@ this.removeSymbolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.applyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ClearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.shiftUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.shiftDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.shiftLeftToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -76,10 +79,9 @@ this.dlgOpen = new System.Windows.Forms.OpenFileDialog(); this.btnBaseline = new System.Windows.Forms.Button(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); - this.btnClear = new System.Windows.Forms.Button(); - this.ClearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.chkLeftSide = new System.Windows.Forms.CheckBox(); this.chkTopSide = new System.Windows.Forms.CheckBox(); + this.openDEVToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.nudX)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudY)).BeginInit(); this.panel1.SuspendLayout(); @@ -230,6 +232,18 @@ this.panel1.Size = new System.Drawing.Size(120, 121); this.panel1.TabIndex = 9; // + // btnClear + // + this.btnClear.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.btnClear.Location = new System.Drawing.Point(7, 8); + this.btnClear.Name = "btnClear"; + this.btnClear.Size = new System.Drawing.Size(30, 30); + this.btnClear.TabIndex = 7; + this.btnClear.Text = "○"; + this.toolTip1.SetToolTip(this.btnClear, "Clear canvas"); + this.btnClear.UseVisualStyleBackColor = true; + this.btnClear.Click += new System.EventHandler(this.btnClear_Click); + // // btnMirrorY // this.btnMirrorY.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); @@ -416,6 +430,8 @@ this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.newToolStripMenuItem, this.openToolStripMenuItem, + this.openDEVToolStripMenuItem, + this.saveDEVToolStripMenuItem, this.saveToolStripMenuItem, this.saveAsToolStripMenuItem, this.exitToolStripMenuItem}); @@ -443,6 +459,13 @@ this.openToolStripMenuItem.Text = "Open"; this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); // + // saveDEVToolStripMenuItem + // + this.saveDEVToolStripMenuItem.Name = "saveDEVToolStripMenuItem"; + this.saveDEVToolStripMenuItem.Size = new System.Drawing.Size(184, 22); + this.saveDEVToolStripMenuItem.Text = "Save as (new format)"; + this.saveDEVToolStripMenuItem.Click += new System.EventHandler(this.saveJSONToolStripMenuItem_Click); + // // saveToolStripMenuItem // this.saveToolStripMenuItem.Image = global::McBitFont.Properties.Resources.Famfamfam_Silk_Disk_16; @@ -568,6 +591,15 @@ this.toolsToolStripMenuItem.Size = new System.Drawing.Size(47, 20); this.toolsToolStripMenuItem.Text = "Tools"; // + // ClearToolStripMenuItem + // + this.ClearToolStripMenuItem.Name = "ClearToolStripMenuItem"; + this.ClearToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+W"; + this.ClearToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.W))); + this.ClearToolStripMenuItem.Size = new System.Drawing.Size(197, 22); + this.ClearToolStripMenuItem.Text = "Clear canvas"; + this.ClearToolStripMenuItem.Click += new System.EventHandler(this.btnClear_Click); + // // shiftUpToolStripMenuItem // this.shiftUpToolStripMenuItem.Image = global::McBitFont.Properties.Resources.arrow_top; @@ -657,7 +689,7 @@ // dlgSave // this.dlgSave.DefaultExt = "mbf"; - this.dlgSave.Filter = "McBitFont files|*.mbf|All files|*.*"; + this.dlgSave.Filter = "McBitFont files|*.mbf|McBitFont new format|*.mbfont|All files|*.*"; // // dlgOpen // @@ -682,27 +714,6 @@ this.toolTip1.InitialDelay = 500; this.toolTip1.ReshowDelay = 100; // - // btnClear - // - this.btnClear.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.btnClear.Location = new System.Drawing.Point(7, 8); - this.btnClear.Name = "btnClear"; - this.btnClear.Size = new System.Drawing.Size(30, 30); - this.btnClear.TabIndex = 7; - this.btnClear.Text = "○"; - this.toolTip1.SetToolTip(this.btnClear, "Clear canvas"); - this.btnClear.UseVisualStyleBackColor = true; - this.btnClear.Click += new System.EventHandler(this.btnClear_Click); - // - // ClearToolStripMenuItem - // - this.ClearToolStripMenuItem.Name = "ClearToolStripMenuItem"; - this.ClearToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+W"; - this.ClearToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.W))); - this.ClearToolStripMenuItem.Size = new System.Drawing.Size(197, 22); - this.ClearToolStripMenuItem.Text = "Clear canvas"; - this.ClearToolStripMenuItem.Click += new System.EventHandler(this.btnClear_Click); - // // chkLeftSide // this.chkLeftSide.AutoSize = true; @@ -725,6 +736,14 @@ this.toolTip1.SetToolTip(this.chkTopSide, "Height changes will be made on Top/Bottom side"); this.chkTopSide.UseVisualStyleBackColor = true; // + // openDEVToolStripMenuItem + // + this.openDEVToolStripMenuItem.Name = "openDEVToolStripMenuItem"; + this.openDEVToolStripMenuItem.Size = new System.Drawing.Size(184, 22); + this.openDEVToolStripMenuItem.Text = "Open DEV"; + this.openDEVToolStripMenuItem.Visible = false; + this.openDEVToolStripMenuItem.Click += new System.EventHandler(this.openDEVToolStripMenuItem_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -824,6 +843,8 @@ private System.Windows.Forms.ToolStripMenuItem ClearToolStripMenuItem; private System.Windows.Forms.CheckBox chkLeftSide; private System.Windows.Forms.CheckBox chkTopSide; + private System.Windows.Forms.ToolStripMenuItem saveDEVToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem openDEVToolStripMenuItem; } } diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index d03f549..4bc2635 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -1,25 +1,29 @@ -using System; +using MessagePack; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; +using System.Drawing.Drawing2D; +using System.IO; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; -using System.Runtime.InteropServices; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; -using System.Runtime.InteropServices.ComTypes; -using System.Diagnostics; -using System.Drawing.Drawing2D; + namespace McBitFont { public partial class MainForm : Form { + [Serializable] + [MessagePackObject] public struct FrameMiniature { public FrameMiniature(int cc, int ww, int hh) { code = cc; @@ -27,17 +31,26 @@ namespace McBitFont { height = hh; data = new bool[ww, hh]; } + [Key(0)] public int code; + [Key(1)] public int width; + [Key(2)] public int height; + [Key(3)] public bool[,] data; }; [Serializable] + [MessagePackObject] public struct SaveBlock { + [Key(4)] public bool monospaced; + [Key(5)] public int codepage; + [Key(6)] public int baseline; + [Key(7)] public List frames; } @@ -51,7 +64,7 @@ namespace McBitFont { public bool monospaced = false; bool modified = false; bool prjModified = false; - public const string version = "1.6"; + public const string version = "1.7"; public string prjName = "Untitled"; public string prjFileName = ""; public int codepage = 1251; @@ -810,6 +823,75 @@ namespace McBitFont { dotPanel.Refresh(); } + private void saveJSONToolStripMenuItem_Click(object sender, EventArgs e) { + checkModifiedFrame(); + if (dlgSave.ShowDialog() == DialogResult.OK) { + SaveBlock sav; + sav.monospaced = monospaced; + sav.frames = frames; + sav.codepage = codepage; + sav.baseline = baseline; + using (Stream ms = File.OpenWrite(dlgSave.FileName)) { + // TODO: Serializer here + MessagePackSerializer.Serialize(ms, sav); + ms.Close(); + } + prjModified = false; + prjName = Path.GetFileNameWithoutExtension(dlgSave.FileName); + prjFileName = dlgSave.FileName; + this.Text = "McBitFont " + version + " - " + prjName; + } + } + + private void openDEVToolStripMenuItem_Click(object sender, EventArgs e) { + if (prjModified) { + if (MessageBox.Show("The project is modified.\nDo you want to save it first?", "Project was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) { + saveAsToolStripMenuItem.PerformClick(); + return; + } + } + if (dlgOpen.ShowDialog() == DialogResult.OK) { + SaveBlock sav; + + var filename = dlgOpen.FileName; + using (FileStream fs = File.Open(filename, FileMode.Open)) { + sav = MessagePackSerializer.Deserialize(fs); + fs.Close(); + } + monospaced = sav.monospaced; + codepage = sav.codepage; + baseline = sav.baseline; + lblType.Text = monospaced ? "Monospaced" : "Variable width / Single"; + frames = sav.frames; + miniList.Items.Clear(); + ilMiniatures.Images.Clear(); + foreach (FrameMiniature ff in frames) { + var s = ff.code.ToString().PadLeft(3, '0'); + var sss = decodeSymbol(ff.code); + ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff)); + miniList.Items.Add(s, s + ' ' + sss, s); + } + nudX.ValueChanged -= nudX_ValueChanged; + nudY.ValueChanged -= nudY_ValueChanged; + nudX.Value = frames.First().width; + nudY.Value = frames.First().height; + dotResize((int)nudX.Value, (int)nudY.Value); + nudX.ValueChanged += nudX_ValueChanged; + nudY.ValueChanged += nudY_ValueChanged; + f = copyFrame(frames.First()); + dotPanel.Refresh(); + miniList.Refresh(); + modified = false; + prjModified = false; + + prjFileName = filename; + prjName = Path.GetFileNameWithoutExtension(filename); + this.Text = "McBitFont " + version + " - " + prjName; + checkForAdd(); + fbuffer = false; + } + } + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (prjModified) { if (MessageBox.Show("The project is modified.\nAre you sure you want to quit?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { diff --git a/McBitFont/Form1.resx b/McBitFont/Form1.resx index 840ae1f..398ee74 100644 --- a/McBitFont/Form1.resx +++ b/McBitFont/Form1.resx @@ -132,6 +132,9 @@ 336, 17 + + 436, 17 + diff --git a/McBitFont/McBitFont.csproj b/McBitFont/McBitFont.csproj index bd0e30d..8d5ff44 100644 --- a/McBitFont/McBitFont.csproj +++ b/McBitFont/McBitFont.csproj @@ -27,6 +27,8 @@ false false true + + AnyCPU @@ -51,8 +53,39 @@ icon_64.ico + + ..\packages\MessagePack.3.1.3\lib\net472\MessagePack.dll + + + ..\packages\MessagePack.Annotations.3.1.3\lib\netstandard2.0\MessagePack.Annotations.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\Microsoft.NET.StringTools.17.11.4\lib\net472\Microsoft.NET.StringTools.dll + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Collections.Immutable.8.0.0\lib\net462\System.Collections.Immutable.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + @@ -112,6 +145,7 @@ Resources.resx True + SettingsSingleFileGenerator Settings.Designer.cs @@ -205,4 +239,11 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/McBitFont/Properties/AssemblyInfo.cs b/McBitFont/Properties/AssemblyInfo.cs index 1c9ea79..cb38638 100644 --- a/McBitFont/Properties/AssemblyInfo.cs +++ b/McBitFont/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Можно задать все значения или принять номера сборки и редакции по умолчанию // используя "*", как показано ниже: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.0.0")] -[assembly: AssemblyFileVersion("1.6.0.0")] +[assembly: AssemblyVersion("1.7.0.0")] +[assembly: AssemblyFileVersion("1.7.0.0")] diff --git a/McBitFont/packages.config b/McBitFont/packages.config new file mode 100644 index 0000000..bb9683a --- /dev/null +++ b/McBitFont/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TODO.txt b/TODO.txt index 383408f..ba8f222 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,6 @@ Application: -v Implement "Save" menu +V Implement "Save" menu +V Implement new saved font file format Functionality: - Context menu in symbol navigator