302 lines
9.7 KiB
C#
302 lines
9.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms.VisualStyles;
|
|
|
|
namespace McBitFont {
|
|
public partial class Form1 : Form {
|
|
|
|
struct FrameMiniature {
|
|
public int code;
|
|
public int width;
|
|
public int height;
|
|
public bool[,] data;
|
|
};
|
|
|
|
FrameMiniature f;
|
|
private int cellSize = 10;
|
|
private int dotWidth, dotHeight;
|
|
private Panel[,] dots = new Panel[255,255];
|
|
|
|
public Form1() {
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e) {
|
|
int i, j;
|
|
|
|
dotWidth = (int)nudX.Value;
|
|
dotHeight = (int)nudY.Value;
|
|
|
|
for (i = 0; i < dotWidth; i++) {
|
|
for (j = 0; j < dotHeight; j++) {
|
|
Panel p = new Panel();
|
|
dots[i,j] = NewDot(i, j);
|
|
}
|
|
}
|
|
|
|
cbZoom.SelectedIndex = 3;
|
|
cbZoom.SelectedIndexChanged += cbZoom_SelectedIndexChanged;
|
|
|
|
f.code = 1;
|
|
f.width = dotWidth;
|
|
f.height = dotHeight;
|
|
f.data = new bool[dotWidth, dotHeight];
|
|
|
|
}
|
|
|
|
private Panel NewDot(int i, int j) {
|
|
Panel p = new Panel();
|
|
p.Parent = dotPanel;
|
|
p.Width = cellSize; p.Height = cellSize;
|
|
p.BackColor = Color.White;
|
|
p.BorderStyle = BorderStyle.None;
|
|
p.Left = 5 + i * (cellSize + 1);
|
|
p.Top = 5 + j * (cellSize + 1);
|
|
p.Tag = i.ToString() + ',' + j.ToString();
|
|
p.MouseMove += dot_MouseMove;
|
|
p.MouseDown += dot_MouseMove;
|
|
//p.Paint += dotPanel_Paint;
|
|
return p;
|
|
}
|
|
|
|
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 nudX_ValueChanged(object sender, EventArgs e) {
|
|
dotResize((int)nudX.Value, dotHeight);
|
|
}
|
|
|
|
private void nudY_ValueChanged(object sender, EventArgs e) {
|
|
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;
|
|
|
|
//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;
|
|
}
|
|
|
|
private void cbZoom_SelectedIndexChanged(object sender, EventArgs e) {
|
|
cellSize = Convert.ToInt32(cbZoom.Text);
|
|
dotScale();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dotPanel_MouseMove(object sender, MouseEventArgs e) {
|
|
Panel p = (Panel)sender;
|
|
p.Capture = false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnMirrorX_Click(object sender, EventArgs e) {
|
|
int a, b, j;
|
|
Color 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--;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnMirrorY_Click(object sender, EventArgs e) {
|
|
int a, b, i;
|
|
Color 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--;
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
private void dotScale() {
|
|
bool large = dotWidth * dotHeight > 12 * 12;
|
|
int gap = (cellSize < 5) ? 0 : 1;
|
|
|
|
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 = 5 + i * (cellSize + gap);
|
|
dots[i, j].Top = 5 + j * (cellSize + gap);
|
|
if (large) pbZoom.PerformStep();
|
|
}
|
|
}
|
|
if (large) {
|
|
dotPanel.Visible = true;
|
|
pbZoom.Visible = false;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|