private void Form1_Load(object sender, EventArgs e) { borderboxGraphics = BorderPictureBox.CreateGraphics(); pictureBox1.Controls.Add(BorderPictureBox); BorderPictureBox.Location = new Point(0, 0); g = Graphics.FromImage(DrawArea); }
private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (CurrentTool == Tools.BorderMaker) { BorderIsDrawn = false; BorderPictureBox.Invalidate(); if (border.First().Count == 0) { return; } full_border.Clear(); // all pixels of border border.First().Add(border.First().First()); // make border circullar for (int i = 0; i < border.First().Count() - 1; i++) { bresenham(border.First()[i].X, border.First()[i].Y, border.First()[i + 1].X, border.First()[i + 1].Y, ref full_border);//calculate all points of border 1->2, 2 ->3 .. n->1 // full_border.RemoveAt(full_border.Count() - 1); // remove duplicate } } else if (CurrentTool == Tools.Marker) { g.DrawLine(new Pen(CurrentColor, width_marker), p_marker, e.Location); } }
private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { DrawArea = Bitmap.FromFile(openFileDialog1.FileName) as Bitmap; pictureBox1.Size = new Size(DrawArea.Width, DrawArea.Height); g = Graphics.FromImage(DrawArea); BorderPictureBox.Size = pictureBox1.Size; BorderPictureBox.Invalidate(); }
private void click_pb(object sender, EventArgs e) { if (sender is BorderPictureBox) { BorderPictureBox p = sender as BorderPictureBox; p.Image = pb.Image; p.ForeColor = pb.ForeColor; } return; }
public TileEditorForm() { panel = new Panel(); panel.Top = 100; panel.Left = 10; MenuStrip ms = new MenuStrip(); this.Controls.Add(ms); ToolStripMenuItem item = new ToolStripMenuItem("File"); item.DropDownItems.Add("New Tileset"); item.DropDownItems[0].Click += new EventHandler(new_tset_click); item.DropDownItems.Add("Load Tileset Image"); item.DropDownItems[1].Click += new EventHandler(load_img_click); item.DropDownItems.Add("Save Tileset"); item.DropDownItems[2].Click += new EventHandler(save_tset_click); ms.Items.Add(item); num = new NumericUpDown(); num.Top = 30; num.Left = 10; num.Enabled = false; this.Controls.Add(num); pb = new BorderPictureBox(); pb.Top = 30; pb.Left = 150; pb.BorderStyle = BorderStyle.FixedSingle; pb.Size = new Size(32, 32); pb.SizeMode = PictureBoxSizeMode.StretchImage; pb.Enabled = false; pb.Click += new EventHandler(click_main_pb); bef = pb.ForeColor; this.Controls.Add(pb); Button b = new Button(); b.Text = "FILL"; b.Top = 30; b.Left = 200; b.Click += new EventHandler(bclick); this.Controls.Add(b); panel.BorderStyle = BorderStyle.FixedSingle; panel.Size = new Size(800, 600); panel.AutoScroll = true; this.Controls.Add(panel); }
private void click_main_pb(object sender, EventArgs e) { if (sender is BorderPictureBox) { BorderPictureBox p = sender as BorderPictureBox; //p.Image = pb.Image; if (p.ForeColor == Color.Red) { p.ForeColor = bef; } else { p.ForeColor = Color.Red; //pb.ForeColor; } } return; }
private void bclick(object o, EventArgs e) { var result = MessageBox.Show("Are you sure you want to fill an entire area?", "Fill area", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } foreach (object obj in panel.Controls) { if (obj is BorderPictureBox) { BorderPictureBox bpb = obj as BorderPictureBox; bpb.Image = pb.Image; bpb.ForeColor = pb.ForeColor; } } }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (CurrentTool == Tools.BorderMaker) { if (BorderIsDrawn && !border.First().Contains(e.Location)) { border.First().Add(e.Location); } BorderPictureBox.Invalidate(); } else if (CurrentTool == Tools.Marker) { g.DrawLine(new Pen(CurrentColor, width_marker), p_marker, e.Location); p_marker = e.Location; } } }
private void new_tset_click(object sender, EventArgs e) { Console.WriteLine("Lojz."); TileSizeInputForm tsif = new TileSizeInputForm(); tsif.ShowDialog(); panel.Controls.Clear(); for (int i = 0; i < Globals.t_width; i++) { for (int j = 0; j < Globals.t_height; j++) { BorderPictureBox pict = new BorderPictureBox(); //pict.ForeColor = Color.Red; pict.Top = j * 32; pict.Left = i * 32; pict.Size = new Size(32, 32); pict.BorderStyle = BorderStyle.FixedSingle; pict.Click += new EventHandler(click_pb); panel.Controls.Add(pict); } } Console.WriteLine("Created new Tileset of size {0}x{1}", Globals.t_width, Globals.t_height); }
public static void ExportTileset(Panel p, string out_file) { TileMapHeader header; header.identifier = 1346456916; //BitConverter.ToInt32(byte[] {'T', 'M', 'A', 'P'}); header.width = (ushort)t_width; header.height = (ushort)t_height; header.tileset_id = 0; // TODO Console.WriteLine("Exporting tileset ..."); Tile[] tilez = new Tile[t_width * t_height]; foreach (object o in p.Controls) { if (o is BorderPictureBox) { BorderPictureBox pb = o as BorderPictureBox; int y = pb.Top / 32; int x = pb.Left / 32; int id = (int)t_height * x + y; Console.WriteLine("Calculated ID: {0}", id); Console.WriteLine("From X:{0} Y:{1} and T_HEIGHT:{2}", x, y, t_height); tilez[id].passable = 1; if (pb.ForeColor == Color.Red) { tilez[id].passable = 0; } tilez[id].terrain_tag = 0; // TODO tilez[id].texture_id = 0; for (int i = 0; i < tiles.Length; i++) { Console.WriteLine("Adding {0}", i); if (pb.Image == tiles[i]) { tilez[id].texture_id = (ushort)i; break; } } Console.WriteLine("Added tile {0}", id); } } int size = Marshal.SizeOf(header); byte[] arr = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(header, ptr, true); Marshal.Copy(ptr, arr, 0, size); Marshal.FreeHGlobal(ptr); // Output File.WriteAllBytes(out_file, arr); Console.WriteLine("Written header: {0} bytes", size); foreach (Tile t in tilez) { size = Marshal.SizeOf(t); arr = new byte[size]; ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(t, ptr, true); Marshal.Copy(ptr, arr, 0, size); Marshal.FreeHGlobal(ptr); // Output Globals.AppendAllBytes(out_file, arr); Console.WriteLine("Written tiles: {0} bytes", size); } Console.WriteLine("Finished!"); }
private bool magic_border(Point start, Point beam_start, Color clr_img, out int rightmost, bool inner = false) { List <Point> local_border = new List <Point>(); int count_intersections = 0; List <int> intersct = new List <int>(); Point LeftmostBeam = new Point(start.X, start.Y); Point RightMostBeam = new Point(start.X, start.Y); Point curr_p = new Point(start.X, start.Y); int dir = 6; Point view_p = new Point(); do { int old = dir; int i; for (i = 0; i < 8; ++i) { view_p = next_point(dir, curr_p); if (view_p.X < 0 || view_p.X >= DrawArea.Width || view_p.Y < 0 || view_p.Y >= DrawArea.Height) { break; } else if (!equal_color(DrawArea.GetPixel(view_p.X, view_p.Y), clr_img)) { break; } dir += 1; if (dir > 7) { dir = 0; } } local_border.Add(curr_p); if (curr_p.Y == beam_start.Y) { if (curr_p.X > RightMostBeam.X) { RightMostBeam = curr_p; } if (curr_p.X < LeftmostBeam.X) { LeftmostBeam = curr_p; } if (curr_p.X > beam_start.X) { intersct.Add(curr_p.X); } } curr_p = view_p; if (dir - 2 < 0) { dir += 8; } dir -= 2; if (i == 8) // single point { break; } } while (curr_p != start); if (!inner) { intersct.Sort(); int old_x = int.MinValue; foreach (var x in intersct) { if (old_x + 1 != x) { count_intersections++; } old_x = x; } } border.Add(local_border); BorderPictureBox.Invalidate(); rightmost = RightMostBeam.X; if (inner || RightMostBeam == LeftmostBeam || count_intersections % 2 == 0) { foreach (var p in local_border) { inner_border.Add(p); } return(false); } else { foreach (var p in local_border) { full_border.Add(p); } return(true); } }
private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (CurrentTool == Tools.BorderMaker) { border.Clear(); BorderIsDrawn = true; border.Add(new List <Point>()); border.Last().Add(e.Location); BorderPictureBox.Invalidate(); } else if (CurrentTool == Tools.Fill) { colored_lines.Clear(); rec_fill(e.Location); } else if (CurrentTool == Tools.ImageFill) { colored_lines.Clear(); if (openFileDialog2.ShowDialog() != DialogResult.OK) { return; } ImageFill = Image.FromFile(openFileDialog2.FileName) as Bitmap; fill_image(e.Location, new Point(0, 0)); } else if (CurrentTool == Tools.MagicWand) { full_border.Clear(); border.Clear(); colored_lines.Clear(); inner_border.Clear(); int x; Point start = e.Location; x = start.X; Color c = DrawArea.GetPixel(x, start.Y); while (x < DrawArea.Width) { Color _c = DrawArea.GetPixel(x, start.Y); if (!equal_color(_c, c) && magic_border(new Point(x, start.Y), start, c, out x)) { break; } else { x++; } } /* if (full_border.Count == 0) * { * for (int y = 0; y != DrawArea.Height; y++) * { * * ScanLine(new Point(-1,y), new Point(-1, DrawArea.Width), c); * * } * } * else * { * int top = full_border.Last().Y; * for (int y = full_border.First().Y; y != top; y++) * { * List<Point> ps = full_border.Where((Point p) => { return (p.Y == y) && is_not_hill(p); }).ToList(); * for (int i = 0; i < ps.Count - 1; i++) * { * ScanLine(ps[i], ps[i + 1], c); * } * } * * }*/ BorderPictureBox.Invalidate(); } else if (CurrentTool == Tools.Marker) { p_marker = e.Location; } } }