//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
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;
namespace DarkWynter.App
{
using Color = System.Drawing.Color;
using Point = System.Drawing.Point;
public class LevelEditorPanel : UserControl
{
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()
{
this.pictureBoxMapView = new PictureBox();
this.colorSelectionButton = new Button();
this.numericUpDownGreyScaleValue = new NumericUpDown();
this.numericUpDownBrushSize = new NumericUpDown();
//
// pictureBox1
//
this.pictureBoxMapView.BackColor = System.Drawing.Color.Black;
this.pictureBoxMapView.Location = new System.Drawing.Point(0, 0);
this.pictureBoxMapView.Name = "pictureBox1";
this.pictureBoxMapView.Size = new System.Drawing.Size(4096, 4096);
this.pictureBoxMapView.TabIndex = 0;
this.pictureBoxMapView.TabStop = false;
this.pictureBoxMapView.BorderStyle = BorderStyle.Fixed3D;
this.pictureBoxMapView.Click += new System.EventHandler(this.pictureBoxMapView_Click);
//
// 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);
this.Controls.Add(this.pictureBoxMapView);
this.Controls.Add(this.numericUpDownGreyScaleValue);
this.Controls.Add(this.colorSelectionButton);
this.Controls.Add(this.numericUpDownBrushSize);
// New Bitmap
// bmp = new Bitmap("c:/images/image.gif");
bmp = new Bitmap(1024, 1024);
pictureBoxMapView.Image = bmp;
//saveTexture = new Texture2D(GraphicsDevice, bmp.Width, bmp.Height, 0, TextureUsage.AutoGenerateMipMap, SurfaceFormat.Vector4);
saveData = new Vector4[bmp.Width * bmp.Height];
}
//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);
}
}
}