using System; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; //using WinFormsGraphicsDevice; namespace DarkWynter.App { using Color = System.Drawing.Color; using Point = System.Drawing.Point; public class LevelEditorPanel : Panel { public Panel panel; private PictureBox pictureBoxMapView; private Button colorSelectionButton; private NumericUpDown numericUpDownGreyScaleValue; private NumericUpDown numericUpDownBrushSize; // New Bitmap Bitmap bmp; Color currentColor = Color.Red; int brushSize = 50; Texture2D saveTexture; Vector4[] saveData; public LevelEditorPanel(): base() { Initialize(); } protected void Initialize() { this.panel = CreatePanel(ContentLoader.location, ContentLoader.size); this.pictureBoxMapView = new PictureBox(); this.colorSelectionButton = new Button(); this.numericUpDownGreyScaleValue = new NumericUpDown(); this.numericUpDownBrushSize = new NumericUpDown(); // // pictureBox1 // this.pictureBoxMapView.BackColor = System.Drawing.Color.Transparent; this.pictureBoxMapView.Location = new System.Drawing.Point(0, 0); this.pictureBoxMapView.Name = "pictureBox1"; this.pictureBoxMapView.Size = new System.Drawing.Size(500, 500); this.pictureBoxMapView.TabIndex = 0; this.pictureBoxMapView.TabStop = false; this.pictureBoxMapView.BorderStyle = BorderStyle.Fixed3D; this.pictureBoxMapView.Click += new System.EventHandler(this.pictureBoxMapView_Click); // New Bitmap // bmp = new Bitmap("c:/images/image.gif"); bmp = new Bitmap(512, 512); pictureBoxMapView.Image = bmp; //saveTexture = new Texture2D(GraphicsDevice, bmp.Width, bmp.Height, 0, TextureUsage.AutoGenerateMipMap, SurfaceFormat.Vector4); saveData = new Vector4[bmp.Width * bmp.Height]; // // colorSelectionButton // this.colorSelectionButton.Location = new System.Drawing.Point(0, 540); this.colorSelectionButton.Name = "colorSelectionButton"; this.colorSelectionButton.Size = new System.Drawing.Size(107, 25); this.colorSelectionButton.TabIndex = 1; this.colorSelectionButton.Text = "Change Color"; this.colorSelectionButton.UseVisualStyleBackColor = true; this.colorSelectionButton.Click += new System.EventHandler(this.colorSelectionButton_Click); // // numericUpDownGreyScaleValue // this.numericUpDownGreyScaleValue.Location = new System.Drawing.Point(0, 515); this.numericUpDownGreyScaleValue.Maximum = new decimal(new int[] { 255, 0, 0, 0}); this.numericUpDownGreyScaleValue.Name = "numericUpDown1"; this.numericUpDownGreyScaleValue.Size = new System.Drawing.Size(120, 20); this.numericUpDownGreyScaleValue.TabIndex = 2; this.numericUpDownGreyScaleValue.ValueChanged += new System.EventHandler(this.numericUpDownGreyScaleValue_ValueChanged); // // numericUpDownBrushSize // this.numericUpDownBrushSize.Location = new System.Drawing.Point(0, 575); this.numericUpDownBrushSize.Maximum = new decimal(new int[] { 255, 0, 0, 0}); this.numericUpDownBrushSize.Name = "numericUpDown1"; this.numericUpDownBrushSize.Size = new System.Drawing.Size(120, 20); this.numericUpDownBrushSize.TabIndex = 2; this.numericUpDownBrushSize.ValueChanged += new System.EventHandler(this.numericUpDownBrushSize_ValueChanged); panel.Controls.Add(this.pictureBoxMapView); panel.Controls.Add(this.numericUpDownGreyScaleValue); panel.Controls.Add(this.colorSelectionButton); panel.Controls.Add(this.numericUpDownBrushSize); } private Panel CreatePanel(Point location, Size size) { Panel myPanel = new Panel(); myPanel.Location = location; myPanel.Size = size; myPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; myPanel.AutoScroll = true; myPanel.BorderStyle = BorderStyle.Fixed3D; return myPanel; } #region Level Edit private void pictureBoxMapView_Click(object sender, EventArgs e) { MouseEventArgs me = e as MouseEventArgs;//or MouseEventArgs em = (MouseEventArgs)e; // Paint the pixel using brushsize for (int i = -brushSize; i < brushSize; i++) { for (int j = -brushSize; j < brushSize; j++) { // Find x & y relative to center of brush int x = me.X + i; int y = me.Y + j; // If within the bmp bounds if (0 < x && x < bmp.Width && 0 < y && y < bmp.Height) { // Call " Brush-Tip" Function here bmp.SetPixel(x, y, currentColor); } } } // Redraw pictureBoxMapView.Refresh(); } private void colorSelectionButton_Click(object sender, EventArgs e) { // Color Dialog Selection ColorDialog colorDlg = new ColorDialog(); colorDlg.ShowDialog(); currentColor = colorDlg.Color; this.colorSelectionButton.BackColor = currentColor; } private void numericUpDownGreyScaleValue_ValueChanged(object sender, EventArgs e) { // Grey Scale selection int color = (int)this.numericUpDownGreyScaleValue.Value; currentColor = Color.FromArgb(255, color, color, color); this.colorSelectionButton.BackColor = currentColor; } private void numericUpDownBrushSize_ValueChanged(object sender, EventArgs e) { brushSize = (int)this.numericUpDownBrushSize.Value; } #endregion public void SaveHeightMap() { for (int x = 0; x < saveTexture.Width; x++) { for (int y = 0; y < saveTexture.Height; y++) { Color pixelColor = bmp.GetPixel(x, y); saveData[x + y * saveTexture.Width] = new Vector4(pixelColor.R, pixelColor.G, pixelColor.B, pixelColor.A); } } saveTexture.SetData(saveData); saveTexture.Save("heightMap.dds", ImageFileFormat.Dds); } } }