Successfully implemented manual drawing
This commit is contained in:
2
McBitFont/Form1.Designer.cs
generated
2
McBitFont/Form1.Designer.cs
generated
@@ -70,7 +70,6 @@
|
||||
this.dotPanel.Name = "dotPanel";
|
||||
this.dotPanel.Size = new System.Drawing.Size(593, 518);
|
||||
this.dotPanel.TabIndex = 0;
|
||||
this.dotPanel.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dotPanel_Scroll);
|
||||
this.dotPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.dotPanel_Paint);
|
||||
this.dotPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dotPanel_MouseMove);
|
||||
this.dotPanel.Resize += new System.EventHandler(this.cbZoom_SelectedIndexChanged);
|
||||
@@ -368,6 +367,7 @@
|
||||
//
|
||||
this.vScroll.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.vScroll.LargeChange = 25;
|
||||
this.vScroll.Location = new System.Drawing.Point(608, 12);
|
||||
this.vScroll.Name = "vScroll";
|
||||
this.vScroll.Size = new System.Drawing.Size(21, 518);
|
||||
|
@@ -14,6 +14,12 @@ namespace McBitFont {
|
||||
public partial class Form1 : Form {
|
||||
|
||||
struct FrameMiniature {
|
||||
public FrameMiniature(int cc, int ww, int hh) {
|
||||
code = cc;
|
||||
width = ww;
|
||||
height = hh;
|
||||
data = new bool[ww, hh];
|
||||
}
|
||||
public int code;
|
||||
public int width;
|
||||
public int height;
|
||||
@@ -26,14 +32,13 @@ namespace McBitFont {
|
||||
private int pixelOffset = 5;
|
||||
private int gap;
|
||||
private int w, h;
|
||||
//private Panel[,] dots = new Panel[255,255];
|
||||
|
||||
public Form1() {
|
||||
InitializeComponent();
|
||||
this.dotPanel.MouseWheel += new MouseEventHandler(this.dotPanel_MouseWheel);
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e) {
|
||||
int i, j;
|
||||
|
||||
dotWidth = (int)nudX.Value;
|
||||
dotHeight = (int)nudY.Value;
|
||||
@@ -46,24 +51,33 @@ namespace McBitFont {
|
||||
cbZoom.SelectedIndex = 3;
|
||||
cbZoom.SelectedIndexChanged += cbZoom_SelectedIndexChanged;
|
||||
|
||||
f.code = 1;
|
||||
f.width = dotWidth;
|
||||
f.height = dotHeight;
|
||||
f.data = new bool[dotWidth, dotHeight];
|
||||
f = new FrameMiniature(1, dotWidth, dotHeight);
|
||||
|
||||
}
|
||||
|
||||
private void dot_MouseMove(object sender, MouseEventArgs e) {
|
||||
//Panel p = (Panel)sender;
|
||||
|
||||
//if (e.Button == MouseButtons.Left && p.BackColor != Color.Black) {
|
||||
// p.BackColor = Color.Black;
|
||||
//}
|
||||
//if (e.Button == MouseButtons.Right && p.BackColor != Color.White) {
|
||||
// p.BackColor = Color.White;
|
||||
//}
|
||||
//label3.Text = "Over: " + p.Tag;
|
||||
//p.Capture = false;
|
||||
private void dotPanel_MouseWheel(object sender, MouseEventArgs e) {
|
||||
int t = e.Delta / 120;
|
||||
if (e.Delta == 0) return;
|
||||
if (ModifierKeys.HasFlag(Keys.Shift)) {
|
||||
t += cbZoom.SelectedIndex;
|
||||
if (t > cbZoom.Items.Count - 1) return;
|
||||
if (t < 0) return;
|
||||
cbZoom.SelectedIndex = t;
|
||||
} else if (ModifierKeys.HasFlag(Keys.Control)) {
|
||||
if (hScroll.Enabled) {
|
||||
t = t * -1 * (cellSize + gap) + hScroll.Value;
|
||||
if (t < hScroll.Minimum) t = hScroll.Minimum;
|
||||
if (t > hScroll.Maximum) t = hScroll.Maximum;
|
||||
hScroll.Value = t;
|
||||
}
|
||||
} else {
|
||||
if (vScroll.Enabled) {
|
||||
t = t * -1 * (cellSize + gap) + vScroll.Value;
|
||||
if (t < vScroll.Minimum) t = vScroll.Minimum;
|
||||
if (t > vScroll.Maximum) t = vScroll.Maximum;
|
||||
vScroll.Value = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void nudX_ValueChanged(object sender, EventArgs e) {
|
||||
@@ -74,40 +88,29 @@ namespace McBitFont {
|
||||
dotResize(dotWidth, (int)nudY.Value);
|
||||
}
|
||||
|
||||
private void dotResize(int w, int h) {
|
||||
////Width
|
||||
//if (w > dotWidth) {
|
||||
// for (int i = dotWidth; i < w; i++) {
|
||||
// for (int j = 0; j < dotHeight; j++) {
|
||||
// dots[i, j] = NewDot(i, j);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//if (w < dotWidth) {
|
||||
// for (int i = w; i < dotWidth; i++) {
|
||||
// for (int j = 0; j < dotHeight; j++) {
|
||||
// dots[i, j].Dispose();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//dotWidth = w;
|
||||
private void dotResize(int ww, int hh) {
|
||||
int imax, jmax;
|
||||
bool[,] t;
|
||||
|
||||
////Height
|
||||
//if (h > dotHeight) {
|
||||
// for (int i = 0; i < dotWidth; i++) {
|
||||
// for (int j = dotHeight; j < h; j++) {
|
||||
// dots[i, j] = NewDot(i, j);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//if (h < dotHeight) {
|
||||
// for (int i = 0; i < dotWidth; i++) {
|
||||
// for (int j = h; j < dotHeight; j++) {
|
||||
// dots[i, j].Dispose();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//dotHeight = h;
|
||||
if (ww < dotWidth) imax = ww;
|
||||
else imax = dotWidth;
|
||||
if (hh < dotHeight) jmax = hh;
|
||||
else jmax = dotHeight;
|
||||
|
||||
f.width = ww;
|
||||
f.height = hh;
|
||||
t = new bool[ww, hh];
|
||||
for (int i=0; i<imax; i++) {
|
||||
for (int j=0; j<jmax; j++) {
|
||||
t[i, j] = f.data[i, j];
|
||||
}
|
||||
}
|
||||
f.data = t;
|
||||
dotWidth = ww;
|
||||
dotHeight = hh;
|
||||
w = pixelOffset + dotWidth * (cellSize + gap);
|
||||
h = pixelOffset + dotHeight * (cellSize + gap);
|
||||
cbZoom_SelectedIndexChanged(cbZoom, null);
|
||||
}
|
||||
|
||||
private void cbZoom_SelectedIndexChanged(object sender, EventArgs e) {
|
||||
@@ -118,6 +121,7 @@ namespace McBitFont {
|
||||
h = pixelOffset + dotHeight * (cellSize + gap);
|
||||
if (w <= dotPanel.Width) {
|
||||
hScroll.Enabled = false;
|
||||
hScroll.Value = 0;
|
||||
} else {
|
||||
hScroll.Maximum = w - dotPanel.Width + 12;
|
||||
hScroll.Minimum = 0;
|
||||
@@ -126,43 +130,44 @@ namespace McBitFont {
|
||||
|
||||
if (h <= dotPanel.Height) {
|
||||
vScroll.Enabled = false;
|
||||
vScroll.Value = 0;
|
||||
} else {
|
||||
vScroll.Maximum = h - dotPanel.Height + 12;
|
||||
vScroll.Minimum = 0;
|
||||
vScroll.Enabled = true;
|
||||
}
|
||||
|
||||
|
||||
//dotPanel.
|
||||
//dotPanel.ClientSize = s;
|
||||
dotPanel.Invalidate();
|
||||
//dotScale();
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void btnShiftLeft_Click(object sender, EventArgs e) {
|
||||
//for (int j = 0; j < dotHeight; j++) {
|
||||
// Color c = dots[0, j].BackColor;
|
||||
// for (int i = 0; i < dotWidth; i++) {
|
||||
// if (i == dotWidth - 1) {
|
||||
// dots[i, j].BackColor = c;
|
||||
// } else {
|
||||
// dots[i, j].BackColor = dots[i+1, j].BackColor;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
bool c;
|
||||
for (int j = 0; j < dotHeight; j++) {
|
||||
c = f.data[0, j];
|
||||
for (int i = 0; i < dotWidth; i++) {
|
||||
if (i == dotWidth - 1) {
|
||||
f.data[i, j] = c;
|
||||
} else {
|
||||
f.data[i, j] = f.data[i + 1, j];
|
||||
}
|
||||
}
|
||||
}
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void btnShiftRight_Click(object sender, EventArgs e) {
|
||||
//for (int j = 0; j < dotHeight; j++) {
|
||||
// Color c = dots[dotWidth - 1, j].BackColor;
|
||||
// for (int i = dotWidth-1; i >= 0; i--) {
|
||||
// if (i == 0) {
|
||||
// dots[i, j].BackColor = c;
|
||||
// } else {
|
||||
// dots[i, j].BackColor = dots[i - 1, j].BackColor;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
bool c;
|
||||
for (int j = 0; j < dotHeight; j++) {
|
||||
c = f.data[dotWidth - 1, j];
|
||||
for (int i = dotWidth - 1; i >= 0; i--) {
|
||||
if (i == 0) {
|
||||
f.data[i, j] = c;
|
||||
} else {
|
||||
f.data[i, j] = f.data[i - 1, j];
|
||||
}
|
||||
}
|
||||
}
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void dotPanel_MouseMove(object sender, MouseEventArgs e) {
|
||||
@@ -176,7 +181,6 @@ namespace McBitFont {
|
||||
Graphics g = dotPanel.CreateGraphics();
|
||||
SolidBrush sbb = new SolidBrush(Color.Black);
|
||||
f.data[i, j] = true;
|
||||
//dotPanel.Refresh();
|
||||
int x = pixelOffset + i * (cellSize + gap) - hScroll.Value;
|
||||
int y = pixelOffset + j * (cellSize + gap) - vScroll.Value;
|
||||
g.FillRectangle(sbb, x, y, cellSize, cellSize);
|
||||
@@ -185,7 +189,6 @@ namespace McBitFont {
|
||||
Graphics g = dotPanel.CreateGraphics();
|
||||
SolidBrush sbw = new SolidBrush(Color.White);
|
||||
f.data[i, j] = false;
|
||||
//dotPanel.Refresh();
|
||||
int x = pixelOffset + i * (cellSize + gap) - hScroll.Value;
|
||||
int y = pixelOffset + j * (cellSize + gap) - vScroll.Value;
|
||||
g.FillRectangle(sbw, x, y, cellSize, cellSize);
|
||||
@@ -194,115 +197,117 @@ namespace McBitFont {
|
||||
}
|
||||
|
||||
private void btnShiftUp_Click(object sender, EventArgs e) {
|
||||
//for (int i = 0; i < dotWidth; i++) {
|
||||
// Color c = dots[i, 0].BackColor;
|
||||
// for (int j = 0; j < dotHeight; j++) {
|
||||
// if (j == dotHeight - 1) {
|
||||
// dots[i, j].BackColor = c;
|
||||
// } else {
|
||||
// dots[i, j].BackColor = dots[i, j + 1].BackColor;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
bool c;
|
||||
for (int i = 0; i < dotWidth; i++) {
|
||||
c = f.data[i, 0];
|
||||
for (int j = 0; j < dotHeight; j++) {
|
||||
if (j == dotHeight - 1) {
|
||||
f.data[i, j] = c;
|
||||
} else {
|
||||
f.data[i, j] = f.data[i, j + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void btnShiftDown_Click(object sender, EventArgs e) {
|
||||
//for (int i = 0; i < dotWidth; i++) {
|
||||
// Color c = dots[i, dotHeight - 1].BackColor;
|
||||
// for (int j = dotHeight-1; j >= 0; j--) {
|
||||
// if (j == 0) {
|
||||
// dots[i, j].BackColor = c;
|
||||
// } else {
|
||||
// dots[i, j].BackColor = dots[i, j - 1].BackColor;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
bool c;
|
||||
for (int i = 0; i < dotWidth; i++) {
|
||||
c = f.data[i, dotHeight - 1];
|
||||
for (int j = dotHeight-1; j >= 0; j--) {
|
||||
if (j == 0) {
|
||||
f.data[i, j] = c;
|
||||
} else {
|
||||
f.data[i, j] = f.data[i, j - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void btnInvert_Click(object sender, EventArgs e) {
|
||||
//for (int i = 0; i < dotWidth; i++) {
|
||||
// for (int j = 0; j < dotHeight; j++) {
|
||||
// if (dots[i, j].BackColor == Color.White)
|
||||
// dots[i, j].BackColor = Color.Black;
|
||||
// else
|
||||
// dots[i, j].BackColor = Color.White;
|
||||
// }
|
||||
//}
|
||||
for (int i = 0; i < dotWidth; i++) {
|
||||
for (int j = 0; j < dotHeight; j++) {
|
||||
f.data[i, j] = !f.data[i, j];
|
||||
}
|
||||
}
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void btnMirrorX_Click(object sender, EventArgs e) {
|
||||
//int a, b, j;
|
||||
//Color c;
|
||||
int a, b, j;
|
||||
bool c;
|
||||
|
||||
//for (j = 0; j < dotHeight; j++) {
|
||||
// a = 0;
|
||||
// b = dotWidth - 1;
|
||||
// while (a < b) {
|
||||
// c = dots[a, j].BackColor;
|
||||
// dots[a, j].BackColor = dots[b, j].BackColor;
|
||||
// dots[b, j].BackColor = c;
|
||||
// a++;
|
||||
// b--;
|
||||
// }
|
||||
//}
|
||||
for (j = 0; j < dotHeight; j++) {
|
||||
a = 0;
|
||||
b = dotWidth - 1;
|
||||
while (a < b) {
|
||||
c = f.data[a, j];
|
||||
f.data[a, j] = f.data[b, j];
|
||||
f.data[b, j] = c;
|
||||
a++;
|
||||
b--;
|
||||
}
|
||||
}
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void btnMirrorY_Click(object sender, EventArgs e) {
|
||||
//int a, b, i;
|
||||
//Color c;
|
||||
int a, b, i;
|
||||
bool c;
|
||||
|
||||
//for (i = 0; i < dotWidth; i++) {
|
||||
// a = 0;
|
||||
// b = dotHeight - 1;
|
||||
// while (a < b) {
|
||||
// c = dots[i, a].BackColor;
|
||||
// dots[i, a].BackColor = dots[i, b].BackColor;
|
||||
// dots[i, b].BackColor = c;
|
||||
// a++;
|
||||
// b--;
|
||||
// }
|
||||
//}
|
||||
for (i = 0; i < dotWidth; i++) {
|
||||
a = 0;
|
||||
b = dotHeight - 1;
|
||||
while (a < b) {
|
||||
c = f.data[i, a];
|
||||
f.data[i, a] = f.data[i, b];
|
||||
f.data[i, b] = c;
|
||||
a++;
|
||||
b--;
|
||||
}
|
||||
}
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e) {
|
||||
//for (int i = 0; i < dotWidth; i++) {
|
||||
// for (int j = 0; j < dotHeight; j++) {
|
||||
// if (dots[i, j].BackColor == Color.Black) f.data[i, j] = true;
|
||||
// else f.data[i, j] = false;
|
||||
// }
|
||||
//}
|
||||
|
||||
//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);
|
||||
//}
|
||||
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) {
|
||||
//var bmp = new Bitmap(dotWidth, dotHeight);
|
||||
//for (int i=0; i<dotWidth; i++) {
|
||||
// for (int j=0; j<dotHeight; j++) {
|
||||
// bmp.SetPixel(i, j, dots[i, j].BackColor);
|
||||
// }
|
||||
//}
|
||||
//imageList1.Images.RemoveByKey("32");
|
||||
//imageList1.Images.Add("32", (Image)bmp);
|
||||
//miniList.Items[0].ImageKey = "32";
|
||||
//bmp.Dispose();
|
||||
int picSize = (dotWidth > dotHeight) ? dotWidth : dotHeight;
|
||||
var bmp = new Bitmap(picSize, picSize);
|
||||
Color c;
|
||||
for (int i=0; i<dotWidth; i++) {
|
||||
for (int j=0; j<dotHeight; j++) {
|
||||
c = f.data[i, j] ? Color.Black : Color.White;
|
||||
bmp.SetPixel(i, j, c);
|
||||
}
|
||||
}
|
||||
var sizedBMP = new Bitmap(bmp, new Size(50, 50));
|
||||
imageList1.Images.RemoveByKey("32");
|
||||
imageList1.Images.Add("32", (Image)sizedBMP);
|
||||
miniList.Items[0].ImageKey = "32";
|
||||
bmp.Dispose();
|
||||
sizedBMP.Dispose();
|
||||
}
|
||||
|
||||
private void dotPanel_Paint(object sender, PaintEventArgs e) {
|
||||
@@ -322,11 +327,6 @@ namespace McBitFont {
|
||||
}
|
||||
}
|
||||
|
||||
private void dotPanel_Scroll(object sender, ScrollEventArgs e) {
|
||||
//dotPanel.Invalidate();
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void hScroll_ValueChanged(object sender, EventArgs e) {
|
||||
label5.Text = hScroll.Value.ToString();
|
||||
dotPanel.Refresh();
|
||||
@@ -337,29 +337,5 @@ namespace McBitFont {
|
||||
dotPanel.Refresh();
|
||||
}
|
||||
|
||||
private void dotScale() {
|
||||
//bool large = dotWidth * dotHeight > 12 * 12;
|
||||
|
||||
//if (large) {
|
||||
// pbZoom.Maximum = dotWidth * dotHeight;
|
||||
// pbZoom.Value = 0;
|
||||
// pbZoom.Visible = true;
|
||||
// dotPanel.Visible = false;
|
||||
//}
|
||||
//for (int i = 0; i < dotWidth; i++) {
|
||||
// for (int j = 0; j < dotHeight; j++) {
|
||||
// dots[i, j].Width = cellSize; dots[i, j].Height = cellSize;
|
||||
// dots[i, j].Left = pixelOffset + i * (cellSize + gap);
|
||||
// dots[i, j].Top = pixelOffset + j * (cellSize + gap);
|
||||
// if (large) pbZoom.PerformStep();
|
||||
// }
|
||||
//}
|
||||
//if (large) {
|
||||
// dotPanel.Visible = true;
|
||||
// pbZoom.Visible = false;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -125,7 +125,7 @@
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
|
||||
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
||||
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAA8
|
||||
BwAAAk1TRnQBSQFMAwEBAAEoAQABKAEAATIBAAEyAQAE/wEFAQAI/wFCAU0BdgcAAXYDAAEoAwAByAMA
|
||||
BwAAAk1TRnQBSQFMAwEBAAEwAQABMAEAATIBAAEyAQAE/wEFAQAI/wFCAU0BdgcAAXYDAAEoAwAByAMA
|
||||
ATIDAAEBAQABBAUAAYgBExgAAYACAAGAAwACgAEAAYADAAGAAQABgAEAAoACAAPAAQADgAMAAf8CAAH/
|
||||
AwAC/wEAAf8DAAH/AQAB/wEAAv8CAAP//wA1AAEPAYgB8AEAAQ8BiAHwAQABDwGIAfBZAAEHAQABgAEA
|
||||
AQcBAAFwAQABCAEAAXBZAAEHAQABgAEAAQcBAAFwAQABCAEAAXBZAAEHAQABgAEAAQcBAAFwAQABCAEA
|
||||
|
Reference in New Issue
Block a user