Open file; Resize the whole project.
This commit is contained in:
41
McBitFont/Form1.Designer.cs
generated
41
McBitFont/Form1.Designer.cs
generated
@@ -57,7 +57,6 @@
|
||||
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.addSymbolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.removeSymbolToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.fontOptionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.shiftUpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.shiftDownToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@@ -312,11 +311,11 @@
|
||||
//
|
||||
this.outBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.outBox.Font = new System.Drawing.Font("Consolas", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
|
||||
this.outBox.Location = new System.Drawing.Point(685, 105);
|
||||
this.outBox.Location = new System.Drawing.Point(724, 105);
|
||||
this.outBox.Multiline = true;
|
||||
this.outBox.Name = "outBox";
|
||||
this.outBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.outBox.Size = new System.Drawing.Size(96, 40);
|
||||
this.outBox.Size = new System.Drawing.Size(57, 40);
|
||||
this.outBox.TabIndex = 11;
|
||||
this.outBox.Text = "Output text here";
|
||||
//
|
||||
@@ -353,7 +352,7 @@
|
||||
this.button2.Name = "button2";
|
||||
this.button2.Size = new System.Drawing.Size(75, 23);
|
||||
this.button2.TabIndex = 13;
|
||||
this.button2.Text = "button2";
|
||||
this.button2.Text = "Apply";
|
||||
this.button2.UseVisualStyleBackColor = true;
|
||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
||||
//
|
||||
@@ -382,11 +381,11 @@
|
||||
//
|
||||
this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(683, 89);
|
||||
this.label5.Location = new System.Drawing.Point(670, 135);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(35, 13);
|
||||
this.label5.Size = new System.Drawing.Size(24, 13);
|
||||
this.label5.TabIndex = 16;
|
||||
this.label5.Text = "label5";
|
||||
this.label5.Text = "X,Y";
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
@@ -415,27 +414,28 @@
|
||||
// newToolStripMenuItem
|
||||
//
|
||||
this.newToolStripMenuItem.Name = "newToolStripMenuItem";
|
||||
this.newToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.newToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
|
||||
this.newToolStripMenuItem.Text = "New";
|
||||
this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);
|
||||
//
|
||||
// openToolStripMenuItem
|
||||
//
|
||||
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
|
||||
this.openToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.openToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
|
||||
this.openToolStripMenuItem.Text = "Open";
|
||||
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.saveToolStripMenuItem.Text = "Save";
|
||||
this.saveToolStripMenuItem.Text = "Save as";
|
||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
||||
//
|
||||
// exitToolStripMenuItem
|
||||
//
|
||||
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.exitToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
|
||||
this.exitToolStripMenuItem.Text = "Exit";
|
||||
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
|
||||
//
|
||||
@@ -443,30 +443,25 @@
|
||||
//
|
||||
this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.addSymbolToolStripMenuItem,
|
||||
this.removeSymbolToolStripMenuItem,
|
||||
this.fontOptionsToolStripMenuItem});
|
||||
this.removeSymbolToolStripMenuItem});
|
||||
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
|
||||
this.editToolStripMenuItem.Size = new System.Drawing.Size(39, 20);
|
||||
this.editToolStripMenuItem.Text = "Edit";
|
||||
//
|
||||
// addSymbolToolStripMenuItem
|
||||
//
|
||||
this.addSymbolToolStripMenuItem.Enabled = false;
|
||||
this.addSymbolToolStripMenuItem.Name = "addSymbolToolStripMenuItem";
|
||||
this.addSymbolToolStripMenuItem.Size = new System.Drawing.Size(159, 22);
|
||||
this.addSymbolToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.addSymbolToolStripMenuItem.Text = "Add symbol";
|
||||
//
|
||||
// removeSymbolToolStripMenuItem
|
||||
//
|
||||
this.removeSymbolToolStripMenuItem.Enabled = false;
|
||||
this.removeSymbolToolStripMenuItem.Name = "removeSymbolToolStripMenuItem";
|
||||
this.removeSymbolToolStripMenuItem.Size = new System.Drawing.Size(159, 22);
|
||||
this.removeSymbolToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.removeSymbolToolStripMenuItem.Text = "Remove symbol";
|
||||
//
|
||||
// fontOptionsToolStripMenuItem
|
||||
//
|
||||
this.fontOptionsToolStripMenuItem.Name = "fontOptionsToolStripMenuItem";
|
||||
this.fontOptionsToolStripMenuItem.Size = new System.Drawing.Size(159, 22);
|
||||
this.fontOptionsToolStripMenuItem.Text = "Font Options";
|
||||
//
|
||||
// toolsToolStripMenuItem
|
||||
//
|
||||
this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
@@ -532,6 +527,7 @@
|
||||
//
|
||||
// aboutToolStripMenuItem
|
||||
//
|
||||
this.aboutToolStripMenuItem.Enabled = false;
|
||||
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
|
||||
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(52, 20);
|
||||
this.aboutToolStripMenuItem.Text = "About";
|
||||
@@ -544,7 +540,6 @@
|
||||
// dlgOpen
|
||||
//
|
||||
this.dlgOpen.DefaultExt = "mbf";
|
||||
this.dlgOpen.FileName = "openFileDialog1";
|
||||
this.dlgOpen.Filter = "McBitFont files|*.mbf|All files|*.*";
|
||||
//
|
||||
// MainForm
|
||||
@@ -573,6 +568,7 @@
|
||||
this.Name = "MainForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "McBitFont";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
|
||||
this.Load += new System.EventHandler(this.Form1_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudX)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nudY)).EndInit();
|
||||
@@ -619,7 +615,6 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem addSymbolToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem removeSymbolToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem fontOptionsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem toolsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem shiftUpToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem shiftDownToolStripMenuItem;
|
||||
|
@@ -46,6 +46,7 @@ namespace McBitFont {
|
||||
private int w, h;
|
||||
bool monospaced = false;
|
||||
bool modified = false;
|
||||
bool prjModified = true;
|
||||
|
||||
public MainForm() {
|
||||
InitializeComponent();
|
||||
@@ -112,13 +113,59 @@ namespace McBitFont {
|
||||
}
|
||||
|
||||
private void nudX_ValueChanged(object sender, EventArgs e) {
|
||||
if (monospaced) {
|
||||
Bitmap bmp;
|
||||
for (int i = 0; i < frames.Count; i++) {
|
||||
frames[i] = frameResize(frames[i], (int)nudX.Value, dotHeight);
|
||||
bmp = getMiniPictue(frames[i]);
|
||||
string s = frames[i].code.ToString();
|
||||
ilMiniatures.Images.RemoveByKey(s);
|
||||
ilMiniatures.Images.Add(s, (Image)bmp);
|
||||
miniList.Items[s].ImageKey = s;
|
||||
}
|
||||
}
|
||||
prjModified = true;
|
||||
dotResize((int)nudX.Value, dotHeight);
|
||||
}
|
||||
|
||||
private void nudY_ValueChanged(object sender, EventArgs e) {
|
||||
Bitmap bmp;
|
||||
for (int i = 0; i < frames.Count; i++) {
|
||||
frames[i] = frameResize(frames[i], dotWidth, (int)nudY.Value);
|
||||
bmp = getMiniPictue(frames[i]);
|
||||
string s = frames[i].code.ToString();
|
||||
ilMiniatures.Images.RemoveByKey(s);
|
||||
ilMiniatures.Images.Add(s, (Image)bmp);
|
||||
miniList.Items[s].ImageKey = s;
|
||||
}
|
||||
prjModified = true;
|
||||
dotResize(dotWidth, (int)nudY.Value);
|
||||
}
|
||||
|
||||
private FrameMiniature frameResize(FrameMiniature ff, int neww, int newh) {
|
||||
int oldw = ff.width;
|
||||
int oldh = ff.height;
|
||||
int imax, jmax;
|
||||
bool[,] t;
|
||||
|
||||
if (neww < oldw) imax = neww;
|
||||
else imax = oldw;
|
||||
if (newh < oldh) jmax = newh;
|
||||
else jmax = oldh;
|
||||
|
||||
ff.width = neww;
|
||||
ff.height = newh;
|
||||
t = new bool[neww, newh];
|
||||
for (int i=0; i<imax; i++) {
|
||||
for (int j=0;j<jmax; j++) {
|
||||
t[i, j] = ff.data[i, j];
|
||||
}
|
||||
}
|
||||
ff.data = t;
|
||||
|
||||
return ff;
|
||||
}
|
||||
|
||||
private void dotResize(int ww, int hh) {
|
||||
int imax, jmax;
|
||||
bool[,] t;
|
||||
@@ -203,7 +250,7 @@ namespace McBitFont {
|
||||
|
||||
private void dotPanel_MouseMove(object sender, MouseEventArgs e) {
|
||||
if (e.X >= w || e.X <= pixelOffset || e.Y >= h || e.Y <= pixelOffset) return;
|
||||
label3.Text = e.X.ToString() + ',' + e.Y.ToString();
|
||||
//label3.Text = e.X.ToString() + ',' + e.Y.ToString();
|
||||
int i = (e.X - pixelOffset + hScroll.Value) / (cellSize + gap);
|
||||
int j = (e.Y - pixelOffset + vScroll.Value) / (cellSize + gap);
|
||||
label5.Text = i.ToString() + ',' + j.ToString();
|
||||
@@ -339,13 +386,14 @@ namespace McBitFont {
|
||||
ilMiniatures.Images.Add(s, (Image)sizedBMP);
|
||||
sizedBMP.Dispose();
|
||||
modified = false;
|
||||
prjModified = true;
|
||||
}
|
||||
|
||||
private Bitmap getMiniPictue(FrameMiniature m) {
|
||||
int picSize = (m.width > m.height) ? m.width : m.height;
|
||||
var bmp = new Bitmap(picSize, picSize);
|
||||
int imin = m.width < picSize ? (picSize - m.width) / 2 - 1 : 0;
|
||||
int jmin = m.height < picSize ? (picSize - m.height) / 2 - 1 : 0;
|
||||
int imin = m.width < picSize ? (picSize - m.width) / 2 : 0;
|
||||
int jmin = m.height < picSize ? (picSize - m.height) / 2 : 0;
|
||||
Color c;
|
||||
for (int i = 0; i < m.width; i++) {
|
||||
for (int j = 0; j < m.height; j++) {
|
||||
@@ -388,6 +436,12 @@ namespace McBitFont {
|
||||
}
|
||||
|
||||
private void newToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
if (prjModified) {
|
||||
if (MessageBox.Show("The project is modified.\nDo you want to save the changes?", "Project was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) {
|
||||
saveToolStripMenuItem.PerformClick();
|
||||
return;
|
||||
}
|
||||
}
|
||||
New form = new New();
|
||||
if (form.ShowDialog() == DialogResult.OK) {
|
||||
frames.Clear();
|
||||
@@ -419,7 +473,6 @@ namespace McBitFont {
|
||||
monospaced = form.rbMono.Checked;
|
||||
foreach (FrameMiniature ff in frames) {
|
||||
var s = ff.code.ToString();
|
||||
//var c = System.Text.Encoding.ASCII.
|
||||
ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff));
|
||||
miniList.Items.Add(s, s+' '+append+(char)ff.code, s);
|
||||
}
|
||||
@@ -450,39 +503,68 @@ namespace McBitFont {
|
||||
|
||||
private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
if (dlgSave.ShowDialog() == DialogResult.OK) {
|
||||
//MessageBox.Show(dlgSave.FileName);
|
||||
|
||||
SaveBlock sav;
|
||||
sav.monospaced = monospaced;
|
||||
sav.frames = frames;
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
using (System.IO.Stream ms = File.OpenWrite(dlgSave.FileName)) {
|
||||
using (Stream ms = File.OpenWrite(dlgSave.FileName)) {
|
||||
formatter.Serialize(ms, sav);
|
||||
ms.Close();
|
||||
}
|
||||
|
||||
//string filename = @"c:\temp\list.bin";
|
||||
//var list = new List<X>();
|
||||
//list.Add(new X { N = 1, S = "No. 1" });
|
||||
//list.Add(new X { N = 2, S = "No. 2" });
|
||||
//list.Add(new X { N = 3, S = "No. 3" });
|
||||
//BinaryFormatter formatter = new BinaryFormatter();
|
||||
//using (System.IO.Stream ms = File.OpenWrite(filename)) {
|
||||
// formatter.Serialize(ms, list);
|
||||
//}
|
||||
|
||||
//using (FileStream fs = File.Open(filename, FileMode.Open)) {
|
||||
// object obj = formatter.Deserialize(fs);
|
||||
// var newlist = (List<X>)obj;
|
||||
// foreach (X x in newlist) {
|
||||
// Console.Out.WriteLine($"N={x.N}, S={x.S}");
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
prjModified = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void openToolStripMenuItem_Click(object sender, EventArgs e) {
|
||||
if (prjModified) {
|
||||
if (MessageBox.Show("The project is modified.\nDo you want to save the changes?", "Project was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) {
|
||||
saveToolStripMenuItem.PerformClick();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (dlgOpen.ShowDialog() == DialogResult.OK) {
|
||||
//MessageBox.Show(dlgOpen.FileName);
|
||||
SaveBlock sav;
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
|
||||
using (FileStream fs = File.Open(dlgOpen.FileName, FileMode.Open)) {
|
||||
sav = (SaveBlock)formatter.Deserialize(fs);
|
||||
fs.Close();
|
||||
}
|
||||
monospaced = sav.monospaced;
|
||||
frames = sav.frames;
|
||||
miniList.Items.Clear();
|
||||
ilMiniatures.Images.Clear();
|
||||
foreach (FrameMiniature ff in frames) {
|
||||
var s = ff.code.ToString();
|
||||
ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff));
|
||||
miniList.Items.Add(s, s + ' ' + (char)ff.code, 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 = frames.First();
|
||||
dotPanel.Refresh();
|
||||
miniList.Refresh();
|
||||
modified = false;
|
||||
prjModified = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
|
||||
if (prjModified) {
|
||||
if (MessageBox.Show("The project is modified.\nDo you want to save the changes?", "Project was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) {
|
||||
saveToolStripMenuItem.PerformClick();
|
||||
e.Cancel = true;
|
||||
} else {
|
||||
e.Cancel = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void hScroll_ValueChanged(object sender, EventArgs e) {
|
||||
label5.Text = hScroll.Value.ToString();
|
||||
|
Reference in New Issue
Block a user