Basic export text generation done.

This commit is contained in:
Anton Mukhin
2023-05-10 18:23:57 +03:00
parent 54ade42409
commit 04bace7267
4 changed files with 290 additions and 143 deletions

View File

@@ -25,23 +25,24 @@
private void InitializeComponent() {
this.txtOutput = new System.Windows.Forms.RichTextBox();
this.gbScan = new System.Windows.Forms.GroupBox();
this.gbOptions = new System.Windows.Forms.GroupBox();
this.cbComments = new System.Windows.Forms.CheckBox();
this.cbHeader = new System.Windows.Forms.CheckBox();
this.cbOrder = new System.Windows.Forms.ComboBox();
this.cbHDir = new System.Windows.Forms.ComboBox();
this.cbVDir = new System.Windows.Forms.ComboBox();
this.cbHDir = new System.Windows.Forms.ComboBox();
this.cbOrder = new System.Windows.Forms.ComboBox();
this.gbOptions = new System.Windows.Forms.GroupBox();
this.cbHeader = new System.Windows.Forms.CheckBox();
this.cbComments = new System.Windows.Forms.CheckBox();
this.gbNumbers = new System.Windows.Forms.GroupBox();
this.cbNumBase = new System.Windows.Forms.ComboBox();
this.cbNumSize = new System.Windows.Forms.ComboBox();
this.cbBitOrder = new System.Windows.Forms.ComboBox();
this.cbNumSize = new System.Windows.Forms.ComboBox();
this.cbNumBase = new System.Windows.Forms.ComboBox();
this.gbText = new System.Windows.Forms.GroupBox();
this.cbFormat = new System.Windows.Forms.ComboBox();
this.cbLines = new System.Windows.Forms.ComboBox();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.cbLines = new System.Windows.Forms.ComboBox();
this.cbFormat = new System.Windows.Forms.ComboBox();
this.btnGenerate = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.cbZeroes = new System.Windows.Forms.CheckBox();
this.gbScan.SuspendLayout();
this.gbOptions.SuspendLayout();
this.gbNumbers.SuspendLayout();
@@ -62,7 +63,7 @@
this.txtOutput.Location = new System.Drawing.Point(151, 12);
this.txtOutput.Name = "txtOutput";
this.txtOutput.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.txtOutput.Size = new System.Drawing.Size(529, 482);
this.txtOutput.Size = new System.Drawing.Size(529, 507);
this.txtOutput.TabIndex = 0;
this.txtOutput.Text = "// Comment.\nusing System;\n\npublic class Stuff : Form { \n public static void Main(" +
"String args) {\n }\n}\n\n\nTest\n123123\nCode code code\n\nAAAsdasdasd\n!";
@@ -79,40 +80,29 @@
this.gbScan.TabStop = false;
this.gbScan.Text = "Scan";
//
// gbOptions
// cbVDir
//
this.gbOptions.Controls.Add(this.cbHeader);
this.gbOptions.Controls.Add(this.cbComments);
this.gbOptions.Location = new System.Drawing.Point(5, 345);
this.gbOptions.Name = "gbOptions";
this.gbOptions.Size = new System.Drawing.Size(140, 65);
this.gbOptions.TabIndex = 3;
this.gbOptions.TabStop = false;
this.gbOptions.Text = "Options";
this.cbVDir.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbVDir.FormattingEnabled = true;
this.cbVDir.Items.AddRange(new object[] {
"Top to Bottom",
"Bottom to Top"});
this.cbVDir.Location = new System.Drawing.Point(10, 73);
this.cbVDir.Name = "cbVDir";
this.cbVDir.Size = new System.Drawing.Size(121, 21);
this.cbVDir.TabIndex = 2;
//
// cbComments
// cbHDir
//
this.cbComments.AutoSize = true;
this.cbComments.Checked = true;
this.cbComments.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbComments.Location = new System.Drawing.Point(6, 42);
this.cbComments.Name = "cbComments";
this.cbComments.Size = new System.Drawing.Size(75, 17);
this.cbComments.TabIndex = 0;
this.cbComments.Text = "Comments";
this.cbComments.UseVisualStyleBackColor = true;
//
// cbHeader
//
this.cbHeader.AutoSize = true;
this.cbHeader.Checked = true;
this.cbHeader.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbHeader.Location = new System.Drawing.Point(6, 19);
this.cbHeader.Name = "cbHeader";
this.cbHeader.Size = new System.Drawing.Size(86, 17);
this.cbHeader.TabIndex = 1;
this.cbHeader.Text = "Meta header";
this.cbHeader.UseVisualStyleBackColor = true;
this.cbHDir.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbHDir.FormattingEnabled = true;
this.cbHDir.Items.AddRange(new object[] {
"Left to Right",
"Right to Left"});
this.cbHDir.Location = new System.Drawing.Point(10, 46);
this.cbHDir.Name = "cbHDir";
this.cbHDir.Size = new System.Drawing.Size(121, 21);
this.cbHDir.TabIndex = 1;
//
// cbOrder
//
@@ -127,29 +117,41 @@
this.cbOrder.TabIndex = 0;
this.cbOrder.SelectedIndexChanged += new System.EventHandler(this.cbOrder_SelectedIndexChanged);
//
// cbHDir
// gbOptions
//
this.cbHDir.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbHDir.FormattingEnabled = true;
this.cbHDir.Items.AddRange(new object[] {
"Left to Right",
"Right to Left"});
this.cbHDir.Location = new System.Drawing.Point(10, 46);
this.cbHDir.Name = "cbHDir";
this.cbHDir.Size = new System.Drawing.Size(121, 21);
this.cbHDir.TabIndex = 1;
this.gbOptions.Controls.Add(this.cbZeroes);
this.gbOptions.Controls.Add(this.cbHeader);
this.gbOptions.Controls.Add(this.cbComments);
this.gbOptions.Location = new System.Drawing.Point(5, 345);
this.gbOptions.Name = "gbOptions";
this.gbOptions.Size = new System.Drawing.Size(140, 88);
this.gbOptions.TabIndex = 3;
this.gbOptions.TabStop = false;
this.gbOptions.Text = "Options";
//
// cbVDir
// cbHeader
//
this.cbVDir.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbVDir.FormattingEnabled = true;
this.cbVDir.Items.AddRange(new object[] {
"Top to Bottom",
"Bottom to Top"});
this.cbVDir.Location = new System.Drawing.Point(10, 73);
this.cbVDir.Name = "cbVDir";
this.cbVDir.Size = new System.Drawing.Size(121, 21);
this.cbVDir.TabIndex = 2;
this.cbHeader.AutoSize = true;
this.cbHeader.Checked = true;
this.cbHeader.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbHeader.Location = new System.Drawing.Point(6, 19);
this.cbHeader.Name = "cbHeader";
this.cbHeader.Size = new System.Drawing.Size(86, 17);
this.cbHeader.TabIndex = 1;
this.cbHeader.Text = "Meta header";
this.cbHeader.UseVisualStyleBackColor = true;
//
// cbComments
//
this.cbComments.AutoSize = true;
this.cbComments.Checked = true;
this.cbComments.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbComments.Location = new System.Drawing.Point(6, 42);
this.cbComments.Name = "cbComments";
this.cbComments.Size = new System.Drawing.Size(75, 17);
this.cbComments.TabIndex = 0;
this.cbComments.Text = "Comments";
this.cbComments.UseVisualStyleBackColor = true;
//
// gbNumbers
//
@@ -163,18 +165,17 @@
this.gbNumbers.TabStop = false;
this.gbNumbers.Text = "Numbers";
//
// cbNumBase
// cbBitOrder
//
this.cbNumBase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbNumBase.FormattingEnabled = true;
this.cbNumBase.Items.AddRange(new object[] {
"Hexadecimal",
"Binary",
"Decimal"});
this.cbNumBase.Location = new System.Drawing.Point(10, 46);
this.cbNumBase.Name = "cbNumBase";
this.cbNumBase.Size = new System.Drawing.Size(121, 21);
this.cbNumBase.TabIndex = 3;
this.cbBitOrder.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbBitOrder.FormattingEnabled = true;
this.cbBitOrder.Items.AddRange(new object[] {
"LSB Top",
"MSB Top"});
this.cbBitOrder.Location = new System.Drawing.Point(10, 19);
this.cbBitOrder.Name = "cbBitOrder";
this.cbBitOrder.Size = new System.Drawing.Size(121, 21);
this.cbBitOrder.TabIndex = 5;
//
// cbNumSize
//
@@ -189,17 +190,18 @@
this.cbNumSize.Size = new System.Drawing.Size(121, 21);
this.cbNumSize.TabIndex = 4;
//
// cbBitOrder
// cbNumBase
//
this.cbBitOrder.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbBitOrder.FormattingEnabled = true;
this.cbBitOrder.Items.AddRange(new object[] {
"LSB Top",
"MSB Top"});
this.cbBitOrder.Location = new System.Drawing.Point(10, 19);
this.cbBitOrder.Name = "cbBitOrder";
this.cbBitOrder.Size = new System.Drawing.Size(121, 21);
this.cbBitOrder.TabIndex = 5;
this.cbNumBase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbNumBase.FormattingEnabled = true;
this.cbNumBase.Items.AddRange(new object[] {
"Hexadecimal",
"Binary",
"Decimal"});
this.cbNumBase.Location = new System.Drawing.Point(10, 46);
this.cbNumBase.Name = "cbNumBase";
this.cbNumBase.Size = new System.Drawing.Size(121, 21);
this.cbNumBase.TabIndex = 3;
//
// gbText
//
@@ -214,31 +216,15 @@
this.gbText.TabStop = false;
this.gbText.Text = "Text format";
//
// cbFormat
// label1
//
this.cbFormat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbFormat.FormattingEnabled = true;
this.cbFormat.Items.AddRange(new object[] {
"1D C array",
"2D C array",
"Comma separated"});
this.cbFormat.Location = new System.Drawing.Point(10, 19);
this.cbFormat.Name = "cbFormat";
this.cbFormat.Size = new System.Drawing.Size(121, 21);
this.cbFormat.TabIndex = 6;
//
// cbLines
//
this.cbLines.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbLines.FormattingEnabled = true;
this.cbLines.Items.AddRange(new object[] {
"1 Column per line",
"1 Symbol per line",
"X Numbers per line"});
this.cbLines.Location = new System.Drawing.Point(10, 46);
this.cbLines.Name = "cbLines";
this.cbLines.Size = new System.Drawing.Size(121, 21);
this.cbLines.TabIndex = 7;
this.label1.AutoSize = true;
this.label1.Enabled = false;
this.label1.Location = new System.Drawing.Point(10, 76);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 13);
this.label1.TabIndex = 9;
this.label1.Text = "X numbers:";
//
// numericUpDown1
//
@@ -263,19 +249,35 @@
0,
0});
//
// label1
// cbLines
//
this.label1.AutoSize = true;
this.label1.Enabled = false;
this.label1.Location = new System.Drawing.Point(10, 76);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 13);
this.label1.TabIndex = 9;
this.label1.Text = "X numbers:";
this.cbLines.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbLines.FormattingEnabled = true;
this.cbLines.Items.AddRange(new object[] {
"1 Column per line",
"1 Symbol per line",
"X Numbers per line"});
this.cbLines.Location = new System.Drawing.Point(10, 46);
this.cbLines.Name = "cbLines";
this.cbLines.Size = new System.Drawing.Size(121, 21);
this.cbLines.TabIndex = 7;
//
// cbFormat
//
this.cbFormat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbFormat.FormattingEnabled = true;
this.cbFormat.Items.AddRange(new object[] {
"1D C array",
"2D C array",
"Comma separated"});
this.cbFormat.Location = new System.Drawing.Point(10, 19);
this.cbFormat.Name = "cbFormat";
this.cbFormat.Size = new System.Drawing.Size(121, 21);
this.cbFormat.TabIndex = 6;
//
// btnGenerate
//
this.btnGenerate.Location = new System.Drawing.Point(5, 416);
this.btnGenerate.Location = new System.Drawing.Point(5, 439);
this.btnGenerate.Name = "btnGenerate";
this.btnGenerate.Size = new System.Drawing.Size(140, 30);
this.btnGenerate.TabIndex = 6;
@@ -285,19 +287,32 @@
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(5, 464);
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Location = new System.Drawing.Point(5, 487);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(140, 30);
this.btnClose.TabIndex = 7;
this.btnClose.Text = "Close";
this.btnClose.UseVisualStyleBackColor = true;
//
// cbZeroes
//
this.cbZeroes.AutoSize = true;
this.cbZeroes.Checked = true;
this.cbZeroes.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbZeroes.Location = new System.Drawing.Point(6, 65);
this.cbZeroes.Name = "cbZeroes";
this.cbZeroes.Size = new System.Drawing.Size(98, 17);
this.cbZeroes.TabIndex = 2;
this.cbZeroes.Text = "Leading zeroes";
this.cbZeroes.UseVisualStyleBackColor = true;
//
// Export
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnClose;
this.ClientSize = new System.Drawing.Size(692, 506);
this.ClientSize = new System.Drawing.Size(692, 531);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnGenerate);
this.Controls.Add(this.gbText);
@@ -305,7 +320,7 @@
this.Controls.Add(this.gbOptions);
this.Controls.Add(this.gbScan);
this.Controls.Add(this.txtOutput);
this.MinimumSize = new System.Drawing.Size(700, 545);
this.MinimumSize = new System.Drawing.Size(700, 570);
this.Name = "Export";
this.ShowIcon = false;
this.ShowInTaskbar = false;
@@ -344,5 +359,6 @@
private System.Windows.Forms.ComboBox cbFormat;
private System.Windows.Forms.Button btnGenerate;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.CheckBox cbZeroes;
}
}

View File

@@ -11,8 +11,13 @@ using System.Windows.Forms;
namespace McBitFont {
public partial class Export : Form {
public Export() {
private MainForm mainForm;
public Export(object sender) {
InitializeComponent();
mainForm = (MainForm)sender;
}
private void Export_Load(object sender, EventArgs e) {
@@ -82,6 +87,133 @@ namespace McBitFont {
}
private void btnGenerate_Click(object sender, EventArgs e) {
txtOutput.Clear();
int imin, jmin, imax, jmax, idir, jdir;
if (cbOrder.SelectedIndex == 0) {
if (cbHDir.SelectedIndex == 0) {
// Columns; Left to right
imin = 0;
imax = mainForm.dotWidth;
idir = 1;
} else {
// Columns; Right to left
imin = mainForm.dotWidth - 1;
imax = -1;
idir = -1;
}
if (cbVDir.SelectedIndex == 0) {
// Columns; Top to bottom
jmin = 0;
jmax = mainForm.dotHeight;
jdir = 1;
} else {
// Columns; Bottom to top
jmin = mainForm.dotHeight - 1;
jmax = -1;
jdir = -1;
}
} else {
if (cbHDir.SelectedIndex == 0) {
// Rows; Left to right
jmin = 0;
jmax = mainForm.dotHeight;
jdir = 1;
} else {
// Rows; Right to left
jmin = mainForm.dotHeight - 1;
jmax = -1;
jdir = -1;
}
if (cbVDir.SelectedIndex == 0) {
// Rows; Top to bottom
imin = 0;
imax = mainForm.dotWidth;
idir = 1;
} else {
// Rows; Bottom to top
imin = mainForm.dotWidth - 1;
imax = -1;
idir = -1;
}
}
ushort bits = 8;
switch (cbNumSize.SelectedIndex) {
case 0:
bits = 8;
break;
case 1:
bits = 16;
break;
case 2:
bits = 32;
break;
}
int nbase = 16;
string prefix = "0x";
string pref = "";
int pad = 2;
switch (cbNumBase.SelectedIndex) {
case 0:
nbase = 16;
prefix = "0x";
pad = cbZeroes.Checked ? bits / 4 : 0;
break;
case 1:
nbase = 2;
prefix = "0b";
pad = cbZeroes.Checked ? bits : 0;
break;
case 2:
nbase = 10;
prefix = "";
pad = 0;
break;
}
foreach ( MainForm.FrameMiniature f in mainForm.frames) {
// For each frame
string str;
uint b = 0;
int t, x, y;
for (int i = imin; i != imax; i += idir) {
str = "";
for (int j = jmin; j != jmax; j += jdir) {
if (jdir < 0) t = jmin - j;
else t = j;
if (t % bits == 0) b = 0;
if (cbOrder.SelectedIndex == 0) { // Columns
x = i; y = j;
} else { // Rows
x = j; y = i;
}
if (f.data[x, y]) {
if ((cbBitOrder.SelectedIndex == 0 && jdir > 0) || (cbBitOrder.SelectedIndex == 1 && jdir < 0)) {
// LSB on top/Left
b |= (uint)(1 << (t % bits));
} else {
// MSB on top/Left
b |= (uint)(1 << (bits - (t % bits) - 1));
}
}
if (((t + 1) % bits == 0) || j + jdir == jmax) {
if (str.Length > 0) str += " ";
pref = (!cbZeroes.Checked && ((b < 10 && nbase == 16) || (b < 2 && nbase == 2))) ? "" : prefix;
str += pref + Convert.ToString(b, nbase).PadLeft(pad, '0') + ',';
}
}
txtOutput.AppendText(str);
txtOutput.AppendText(Environment.NewLine);
}
txtOutput.AppendText(Environment.NewLine);
}
txtOutput.SelectAll();
ParseText();
}

View File

@@ -313,6 +313,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.miniList.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.miniList.GridLines = true;
this.miniList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.miniList.HideSelection = false;
this.miniList.LargeImageList = this.ilMiniatures;
this.miniList.Location = new System.Drawing.Point(428, 154);

View File

@@ -39,15 +39,15 @@ namespace McBitFont {
}
private FrameMiniature f;
List<FrameMiniature> frames = new List<FrameMiniature>();
public List<FrameMiniature> frames = new List<FrameMiniature>();
private int cellSize = 10;
private int dotWidth, dotHeight;
public int dotWidth, dotHeight;
private int pixelOffset = 5;
private int gap;
private int w, h;
bool monospaced = false;
bool modified = false;
bool prjModified = true;
bool prjModified = false;
public MainForm() {
InitializeComponent();
@@ -70,6 +70,8 @@ namespace McBitFont {
frames.Add(new FrameMiniature(0, dotWidth, dotHeight));
miniList.Items.Add("0", "0 Single", "0");
miniList.Refresh();
miniList.Items[0].Selected = true;
miniList.Select();
f = copyFrame(frames.Find(x => x.code == 0));
ListViewItem_SetSpacing(miniList, 50 + 2, 50 + 22);
@@ -358,26 +360,18 @@ namespace McBitFont {
}
private void button1_Click(object sender, EventArgs e) {
Export eform = new Export();
if (modified) {
if (MessageBox.Show("Current symbol is modified.\nDo you want to save the changes?", "Symbol was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) {
saveFrame();
} else {
f = copyFrame(frames.Find(x => x.code == f.code));
}
modified = false;
}
Export eform = new Export(this);
eform.ShowDialog();
//outBox.Clear();
//String str;
//Byte b = 0;
//for (ushort i = 0; i < dotWidth; i++) {
// str = "";
// for (ushort j = 0; j < dotHeight; j++) {
// if (j % 8 == 0) b = 0;
// if (f.data[i, j]) {
// b |= (Byte)(1 << (j % 8));
// }
// if ( ((j + 1) % 8 == 0) || j+1 == dotHeight ) {
// if (str.Length > 0) str += " ";
// str += "0x" + Convert.ToString(b, 16).PadLeft(2, '0') + ',';
// }
// }
// outBox.AppendText(str);
// outBox.AppendText(Environment.NewLine);
//}
}
private void button2_Click(object sender, EventArgs e) {
@@ -463,6 +457,7 @@ namespace McBitFont {
frames.Add( new FrameMiniature(0, neww, newh));
//f = frames.Find(x => x.code == 0);
append = "Single";
monospaced = false;
} else {
int i;
if (form.cbNotPrintable.Checked) {
@@ -477,8 +472,8 @@ namespace McBitFont {
for (i = 128; i < 256; i++)
frames.Add(new FrameMiniature(i, neww, newh));
}
monospaced = form.rbMono.Checked;
}
monospaced = form.rbMono.Checked;
lblType.Text = monospaced ? "Monospaced" : "Variable width / Single";
foreach (FrameMiniature ff in frames) {
var s = ff.code.ToString();
@@ -504,6 +499,9 @@ namespace McBitFont {
}
modified = false;
}
if (miniList.SelectedItems.Count == 0) {
miniList.Items[0].Selected = true;
}
var sel = miniList.SelectedItems[0];
int code = Convert.ToInt32(sel.ImageKey);
FrameMiniature ff = copyFrame(frames.Find(x => x.code == code));