Multipe Brush Types, Edit Mode, Palette
This commit is contained in:
BIN
Background.png
Normal file
BIN
Background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 243 B |
3
SpriteStacker/Form1.Designer.cs
generated
3
SpriteStacker/Form1.Designer.cs
generated
@@ -43,6 +43,9 @@
|
||||
this.Display.TabIndex = 0;
|
||||
this.Display.TabStop = false;
|
||||
this.Display.Paint += new System.Windows.Forms.PaintEventHandler(this.PaintDisplay);
|
||||
this.Display.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MouseDownEvent);
|
||||
this.Display.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MouseMoveEvent);
|
||||
this.Display.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MouseUpEvent);
|
||||
//
|
||||
// timer1
|
||||
//
|
||||
|
||||
@@ -18,56 +18,54 @@ namespace SpriteStacker
|
||||
{
|
||||
public static Thread MainThread;
|
||||
public static bool running = true;
|
||||
Model model = new Model(25, 25);
|
||||
Model model = new Model(Camera.CanvasWidth, Camera.CanvasHeight);
|
||||
public double LastFT = 0;
|
||||
public bool mouseLeftDown = false;
|
||||
public bool mouseRightDown = false;
|
||||
public bool Rotate = false;
|
||||
public static Rectangle MouseCollider = new Rectangle(0, 0, 100, 100);
|
||||
public static ColourPalette palette = new ColourPalette(24,new Color[] {
|
||||
Color.Black,
|
||||
Color.White,
|
||||
Color.Gray,
|
||||
Color.DarkGreen,
|
||||
Color.Green,
|
||||
Color.LightGreen,
|
||||
Color.GreenYellow,
|
||||
Color.Yellow,
|
||||
Color.Orange,
|
||||
Color.OrangeRed,
|
||||
Color.Red,
|
||||
Color.Purple,
|
||||
Color.Pink,
|
||||
Color.BlueViolet,
|
||||
Color.DarkBlue,
|
||||
Color.Blue,
|
||||
Color.LightBlue,
|
||||
Color.Brown,
|
||||
Color.RosyBrown,
|
||||
Color.SaddleBrown,
|
||||
Color.SandyBrown,
|
||||
Color.Wheat,
|
||||
Color.Beige,
|
||||
Color.Azure
|
||||
});
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
ResizeDisplay();
|
||||
MainThread = new Thread(mainThread);
|
||||
MainThread.SetApartmentState(ApartmentState.STA);
|
||||
MainThread.Start();
|
||||
Camera.SelectedColor = palette.getSelectedColour();
|
||||
model.SetBitmapLayers(new Bitmap[]
|
||||
{
|
||||
Resources._1,
|
||||
Resources._2,
|
||||
Resources._3,
|
||||
Resources._4,
|
||||
Resources._5,
|
||||
Resources._6,
|
||||
Resources._7,
|
||||
Resources._8,
|
||||
Resources._9,
|
||||
Resources._10,
|
||||
Resources._11,
|
||||
Resources._12,
|
||||
Resources._13,
|
||||
Resources._14,
|
||||
Resources._15,
|
||||
Resources._16,
|
||||
Resources._17,
|
||||
Resources._18,
|
||||
Resources._19,
|
||||
Resources._20,
|
||||
Resources._21,
|
||||
Resources._22,
|
||||
Resources._23,
|
||||
Resources._24,
|
||||
Resources._25,
|
||||
Resources._26
|
||||
Resources._1, Resources._2, Resources._3, Resources._4, Resources._5, Resources._6,
|
||||
Resources._7, Resources._8, Resources._9, Resources._10, Resources._11, Resources._12,
|
||||
Resources._13,Resources._14, Resources._15, Resources._16, Resources._17, Resources._18,
|
||||
Resources._19, Resources._20, Resources._21, Resources._22, Resources._23, Resources._24,
|
||||
Resources._25,Resources._26
|
||||
});
|
||||
//model.AddLayers(20);
|
||||
Random rnd = new Random();
|
||||
Color[] colors = new Color[] { Color.FromArgb(255,128,128) };
|
||||
for (int i = 0; i < 150; i++)
|
||||
{
|
||||
for(int j = 0; j < 150; j++)
|
||||
{
|
||||
//int Y = rnd.Next(0, 21);
|
||||
//model.SetData(rnd.Next(0, 25), rnd.Next(0, 25),Y , new Voxel(Color.FromArgb((int)(180 * ( (Y + 1.0) / 22.0 )), (int)(255 * ((Y + 1.0) / 22.0)), (int)(128 * ((Y + 1.0) / 22.0)))));
|
||||
}
|
||||
}
|
||||
//model.DrawLayersToImages();
|
||||
MainThread.Start();
|
||||
}
|
||||
public void mainThread()
|
||||
{
|
||||
@@ -78,8 +76,17 @@ namespace SpriteStacker
|
||||
if (Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds - LastFT > 16)
|
||||
{
|
||||
LastFT = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds;
|
||||
if (Camera.Rotation == 360) Camera.Rotation = 0;
|
||||
Camera.Rotation++;
|
||||
if (Camera.Rotation == 360 || !Rotate && Camera.Rotation != 0) Camera.Rotation = 0;
|
||||
if(Rotate)Camera.Rotation++;
|
||||
if (mouseLeftDown)
|
||||
{
|
||||
if(!palette.Bounds.Contains(MousePosition)) DrawBrush(new Voxel(Camera.SelectedColor));
|
||||
|
||||
}
|
||||
if (mouseRightDown)
|
||||
{
|
||||
if (!palette.Bounds.Contains(MousePosition)) DrawBrush(new Voxel(Color.Transparent));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,6 +94,9 @@ namespace SpriteStacker
|
||||
{
|
||||
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
model.DrawSpriteStack(e.Graphics);
|
||||
palette.Draw(e.Graphics);
|
||||
e.Graphics.ResetTransform();
|
||||
|
||||
}
|
||||
|
||||
private void ResizeDisplay()
|
||||
@@ -96,6 +106,7 @@ namespace SpriteStacker
|
||||
Display.Width = Width;
|
||||
Display.Height = Height - 32;
|
||||
Camera.Width = Width; Camera.Height = Height - 32;
|
||||
palette.CalculateSize();
|
||||
}
|
||||
private void ResizeWindow(object sender, EventArgs e)
|
||||
{
|
||||
@@ -116,13 +127,113 @@ namespace SpriteStacker
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
model = new Model(Camera.CanvasWidth, Camera.CanvasHeight);
|
||||
}
|
||||
private void KeyDownEvent(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.W) Camera.LocY++;
|
||||
if (e.KeyCode == Keys.S) Camera.LocY--;
|
||||
if (e.KeyCode == Keys.A) Camera.LocX++;
|
||||
if (e.KeyCode == Keys.D) Camera.LocX--;
|
||||
BrushType[] types = new BrushType[] { BrushType.Square, BrushType.Circle,BrushType.Spray };
|
||||
if (e.KeyCode == Keys.W) Camera.BrushY = Math.Min(Camera.BrushY + 1,model.Length);
|
||||
if (e.KeyCode == Keys.S) Camera.BrushY = Math.Max(Camera.BrushY -1, 0);
|
||||
if (e.KeyCode == Keys.A) Camera.BrushX = Math.Min(Camera.BrushX + 1, model.Width);
|
||||
if (e.KeyCode == Keys.D) Camera.BrushX = Math.Max(Camera.BrushX - 1, 0);
|
||||
if (e.KeyCode == Keys.Q) Camera.scale++;
|
||||
if (e.KeyCode == Keys.E) Camera.scale--;
|
||||
if (e.KeyCode == Keys.Right) Camera.BrushSize++;
|
||||
if (e.KeyCode == Keys.Left) Camera.BrushSize--;
|
||||
if (e.KeyCode == Keys.Y) Camera.ViewAngle+=0.25f;
|
||||
if (e.KeyCode == Keys.H) Camera.ViewAngle -= 0.25f;
|
||||
if (e.KeyCode == Keys.D1) Config.BackgroundTile += 2;
|
||||
if (e.KeyCode == Keys.D2) Config.BackgroundTile -= 2;
|
||||
if (e.KeyCode == Keys.R) Rotate = !Rotate;
|
||||
if (e.KeyCode == Keys.ShiftKey) Camera.EditMode = !Camera.EditMode;
|
||||
if (e.KeyCode == Keys.Up) model.SetCurrentLayer(Camera.SelectedLayer + 1);
|
||||
if (e.KeyCode == Keys.Down) model.SetCurrentLayer(Math.Max(Camera.SelectedLayer - 1,0));
|
||||
if (e.KeyCode == Keys.Delete) Reset();
|
||||
if (e.KeyCode == Keys.Add)
|
||||
{
|
||||
Camera.CircleIntensity += 0.25;
|
||||
Camera.SprayIntensity++;
|
||||
}
|
||||
if (e.KeyCode == Keys.Subtract) {
|
||||
Camera.CircleIntensity -= 0.25;
|
||||
Camera.SprayIntensity--;
|
||||
}
|
||||
if (e.KeyCode == Keys.U)
|
||||
{
|
||||
Camera.BrushIndex = Camera.BrushIndex+1 >= types.Length ? Camera.BrushIndex = 0: Camera.BrushIndex+1;
|
||||
Camera.type = types[Camera.BrushIndex];
|
||||
}
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
DrawBrush(new Voxel(Camera.SelectedColor));
|
||||
}
|
||||
if (e.KeyCode == Keys.Back)
|
||||
{
|
||||
DrawBrush(new Voxel(Color.Transparent));
|
||||
}
|
||||
}
|
||||
private void DrawBrush(Voxel voxel)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < Camera.BrushSize; i++)
|
||||
{
|
||||
for (int j = 0; j < Camera.BrushSize; j++)
|
||||
{
|
||||
int locx = Math.Min(Math.Max((Camera.BrushX + i - Camera.BrushSize / 2), 0), model.Width - 1);
|
||||
int locy = Math.Min(Math.Max((Camera.BrushY + j - Camera.BrushSize / 2), 0), model.Length - 1);
|
||||
bool paintPixel = false;
|
||||
if (Camera.type == BrushType.Square) paintPixel = true;
|
||||
if (Camera.type == BrushType.Circle && Camera.isWithinCircle(i, j, (int)Math.Floor(Camera.BrushSize / 2.0), (int)(Camera.BrushSize / 2.0), (int)(Camera.BrushSize / 2.0)))
|
||||
{
|
||||
paintPixel = true;
|
||||
}
|
||||
if(Camera.type == BrushType.Spray)
|
||||
{
|
||||
paintPixel = rnd.Next(0, Camera.SprayIntensity + 1) == 1;
|
||||
}
|
||||
if(paintPixel) model.SetData(Math.Min(locx, model.Width - 1), Math.Min(locy, model.Length - 1), Camera.SelectedLayer, voxel);
|
||||
}
|
||||
}
|
||||
model.DrawLayersToImages();
|
||||
}
|
||||
|
||||
private void MouseMoveEvent(object sender, MouseEventArgs e)
|
||||
{
|
||||
MouseCollider.Location = new Point(e.X - 50, e.Y - 50);
|
||||
int PosX = Math.Max(Math.Min((int)Math.Floor((e.X - Width/2 - model.Bounds[Camera.SelectedLayer].Left)/Camera.scale + 0.0),model.Width - 1),0);
|
||||
int PosY = Math.Max(Math.Min((int)Math.Floor((e.Y - Height/2 - model.Bounds[Camera.SelectedLayer].Top) / Camera.scale + 0.0),model.Length - 1) - 3, 0) ;
|
||||
Camera.BrushX = PosX;
|
||||
Camera.BrushY = PosY;
|
||||
palette.SetHover(e.Location);
|
||||
}
|
||||
|
||||
private void MouseDownEvent(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
mouseLeftDown = true;
|
||||
palette.SelectColour();
|
||||
}
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
mouseRightDown = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void MouseUpEvent(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
mouseLeftDown = false;
|
||||
}
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
mouseRightDown = false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
105
SpriteStacker/Model-HR-SD-A172-010.cs
Normal file
105
SpriteStacker/Model-HR-SD-A172-010.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SpriteStacker
|
||||
{
|
||||
public static class Camera
|
||||
{
|
||||
public static int LocX = 300;
|
||||
public static int LocY = 300;
|
||||
public static float Rotation = 0;
|
||||
public static float scale = 10;
|
||||
}
|
||||
public class Voxel
|
||||
{
|
||||
Color VoxelColor;
|
||||
public Voxel(Color voxelColor)
|
||||
{
|
||||
VoxelColor = voxelColor;
|
||||
}
|
||||
public Color GetColor() { return VoxelColor; }
|
||||
public Color[] GetShadedColors(int[] Shadows)
|
||||
{
|
||||
Color[] sides = new Color[6];
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
sides[i] = Color.FromArgb(Math.Max(Math.Min(VoxelColor.R + Shadows[i], 255), 0), Math.Max(Math.Min(VoxelColor.G + Shadows[i], 255), 0), Math.Max(Math.Min(VoxelColor.B + Shadows[i], 255), 0));
|
||||
}
|
||||
return sides;
|
||||
}
|
||||
public Color[] GetShadedColors()
|
||||
{
|
||||
Color[] sides = new Color[6];
|
||||
int[] Shadows = new int[6] { 0, 10, 0, 10, 20, -20 };
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
sides[i] = Color.FromArgb(Math.Max(Math.Min(VoxelColor.R + Shadows[i], 255), 0), Math.Max(Math.Min(VoxelColor.G + Shadows[i], 255), 0), Math.Max(Math.Min(VoxelColor.B + Shadows[i], 255), 0));
|
||||
}
|
||||
return sides;
|
||||
}
|
||||
}
|
||||
public class Model
|
||||
{
|
||||
public List<Bitmap> LayerImages = new List<Bitmap>();
|
||||
List<Voxel[,]> ModelData = new List<Voxel[,]>();
|
||||
int Width;
|
||||
int Length;
|
||||
public Model(int Width, int Length)
|
||||
{
|
||||
this.Width = Width;
|
||||
this.Length = Length;
|
||||
AddLayer();
|
||||
}
|
||||
public void AddLayers(int layerCount)
|
||||
{
|
||||
for (int i = 0; i < layerCount; i++)
|
||||
{
|
||||
AddLayer();
|
||||
}
|
||||
}
|
||||
public void AddLayer()
|
||||
{
|
||||
LayerImages.Add(new Bitmap(Width, Length));
|
||||
ModelData.Add(new Voxel[Width,Length]);
|
||||
}
|
||||
public void DrawSpriteStack(Graphics G)
|
||||
{
|
||||
for (int i = 0; i < ModelData.Count; i++)
|
||||
{
|
||||
G.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
G.ResetTransform();
|
||||
G.TranslateTransform(Camera.LocX,Camera.LocY - (i*Camera.scale));
|
||||
G.RotateTransform(Camera.Rotation);
|
||||
G.DrawImage(LayerImages[i], new Rectangle(new Point(-(int)(Width * Camera.scale)/2, -(int)(Length * Camera.scale) / 2),new Size((int)(Width * Camera.scale), (int)(Length * Camera.scale))));
|
||||
}
|
||||
}
|
||||
public void DrawLayersToImages()
|
||||
{
|
||||
for (int i = 0; i < ModelData.Count; i++)
|
||||
{
|
||||
Bitmap newImage = new Bitmap(Width, Length);
|
||||
for (int x = 0; x < ModelData[i].GetLength(0); x++)
|
||||
{
|
||||
for (int y = 0; y < ModelData[i].GetLength(1); y++)
|
||||
{
|
||||
if (ModelData[i][x, y] != null)
|
||||
{
|
||||
newImage.SetPixel(x, y, ModelData[i][x, y].GetColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
LayerImages[i] = newImage;
|
||||
}
|
||||
}
|
||||
public void SetData(int LocX, int LocY, int Layer, Voxel voxel)
|
||||
{
|
||||
if (Layer >= ModelData.Count) AddLayer();
|
||||
ModelData[Layer][LocX,LocY] = voxel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,136 @@
|
||||
using System;
|
||||
using SpriteStacker.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SpriteStacker
|
||||
{
|
||||
public static class Config
|
||||
{
|
||||
public static Color BasePlateColour = Color.FromArgb(255, 255, 255, 255);
|
||||
public static int BackgroundTile = 2;
|
||||
}
|
||||
public class ColourPalette
|
||||
{
|
||||
int PaletteSize = 24;
|
||||
public Rectangle Bounds;
|
||||
Rectangle[] ColourTiles;
|
||||
Color[] colors;
|
||||
int TileSize = 2;
|
||||
int hoverIndex = -1;
|
||||
int SelectedIndex = 0;
|
||||
public ColourPalette(int paletteSize, Color[] colors)
|
||||
{
|
||||
PaletteSize = paletteSize;
|
||||
this.colors = colors;
|
||||
}
|
||||
public Color getSelectedColour() { return colors[SelectedIndex]; }
|
||||
public void SelectColour()
|
||||
{
|
||||
if (hoverIndex != -1)
|
||||
{
|
||||
SelectedIndex = hoverIndex;
|
||||
Camera.SelectedColor = colors[SelectedIndex];
|
||||
}
|
||||
}
|
||||
public void CalculateSize()
|
||||
{
|
||||
Bounds = new Rectangle(0,Camera.Height/8, 7 * (int)(TileSize * Camera.scale), 5);
|
||||
int HorizontalTiles = (int)(Bounds.Width / (TileSize * Camera.scale)) - 2;
|
||||
ColourTiles = new Rectangle[PaletteSize];
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
for (int i = 0; i < PaletteSize; i++)
|
||||
{
|
||||
ColourTiles[i] = new Rectangle(Bounds.X + (int)Camera.scale + (int)((TileSize * Camera.scale * (x + 1)) / (HorizontalTiles)) + (int)(TileSize * Camera.scale * x),Bounds.Y + (int)(TileSize * Camera.scale * (y + 2)) / HorizontalTiles + (int)(TileSize * Camera.scale * y), (int)(TileSize * Camera.scale), (int)(TileSize * Camera.scale));
|
||||
x++;
|
||||
if (x >= HorizontalTiles)
|
||||
{
|
||||
x = 0;
|
||||
y++;
|
||||
}
|
||||
if (y * (int)(TileSize * Camera.scale) >= Bounds.Height)
|
||||
{
|
||||
Bounds.Height = (y + 10) * (int)(TileSize * Camera.scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHover(Point MouseLocation)
|
||||
{
|
||||
bool Hovering = false; ;
|
||||
for (int i = 0; i < ColourTiles.Length; i++)
|
||||
{
|
||||
if (ColourTiles[i].Contains(MouseLocation))
|
||||
{
|
||||
Hovering = true;
|
||||
hoverIndex = i;
|
||||
}
|
||||
}
|
||||
if (!Hovering) hoverIndex = -1;
|
||||
}
|
||||
public void Draw(Graphics g)
|
||||
{
|
||||
g.ResetTransform();
|
||||
g.FillRectangle(Brushes.White, Bounds);
|
||||
g.DrawRectangle(new Pen(new SolidBrush(Color.Wheat), Camera.scale),Bounds);
|
||||
|
||||
for (int i = 0; i < PaletteSize; i++)
|
||||
{
|
||||
g.ResetTransform();
|
||||
if (i == hoverIndex)
|
||||
{
|
||||
g.ScaleTransform(1.2f, 1.2f);
|
||||
g.TranslateTransform(-(int)(ColourTiles[i].Left * 0.2), -(int)(ColourTiles[i].Top* 0.2));
|
||||
}
|
||||
g.FillRectangle(new SolidBrush(colors[i]), ColourTiles[i]);
|
||||
g.DrawRectangle(new Pen(i == SelectedIndex ? Brushes.Blue : Brushes.Black), ColourTiles[i]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public enum BrushType
|
||||
{
|
||||
Square,
|
||||
Circle,
|
||||
Spray
|
||||
}
|
||||
public static class Camera
|
||||
{
|
||||
public static float ViewAngle = 1.0f;
|
||||
public static int CanvasWidth = 25;
|
||||
public static int CanvasHeight = 25;
|
||||
public static int BrushX = 0;
|
||||
public static int BrushY = 0;
|
||||
public static int LocX = 0;
|
||||
public static int LocY = 50;
|
||||
public static float Rotation = 0;
|
||||
public static int BrushSize = 1;
|
||||
public static float scale = 10;
|
||||
public static int Width;
|
||||
public static int Height;
|
||||
public static int SelectedLayer = 0;
|
||||
public static Color SelectedColor = Color.Yellow;
|
||||
public static BrushType type = BrushType.Square;
|
||||
public static double CircleIntensity =1;
|
||||
public static int SprayIntensity =1;
|
||||
public static int BrushIndex = 0;
|
||||
public static bool EditMode = false;
|
||||
|
||||
public static int square(int a)
|
||||
{
|
||||
return a * a;
|
||||
}
|
||||
public static bool isWithinCircle(int x, int y, int radius, int a, int b)
|
||||
{
|
||||
if (radius <= 2) return true;
|
||||
return square(x - a) + square(y - b) < square(radius)/ CircleIntensity;
|
||||
}
|
||||
}
|
||||
public class Voxel
|
||||
{
|
||||
@@ -49,14 +164,23 @@ namespace SpriteStacker
|
||||
{
|
||||
public List<Bitmap> LayerImages = new List<Bitmap>();
|
||||
List<Voxel[,]> ModelData = new List<Voxel[,]>();
|
||||
int Width;
|
||||
int Length;
|
||||
public int Width;
|
||||
public int Length;
|
||||
public List<Rectangle> Bounds = new List<Rectangle>();
|
||||
public Model(int Width, int Length)
|
||||
{
|
||||
this.Width = Width;
|
||||
this.Length = Length;
|
||||
AddLayer();
|
||||
}
|
||||
public void SetCurrentLayer(int Layer)
|
||||
{
|
||||
if(Layer >= ModelData.Count)
|
||||
{
|
||||
AddLayers(Layer + 1 - ModelData.Count);
|
||||
}
|
||||
Camera.SelectedLayer = Layer;
|
||||
}
|
||||
public void AddLayers(int layerCount)
|
||||
{
|
||||
for (int i = 0; i < layerCount; i++)
|
||||
@@ -68,11 +192,13 @@ namespace SpriteStacker
|
||||
{
|
||||
LayerImages = images.ToList();
|
||||
ModelData.Clear();
|
||||
Bounds.Clear();
|
||||
for(int i = 0;i < LayerImages.Count; i++)
|
||||
{
|
||||
Width = LayerImages[i].Width;
|
||||
Length = LayerImages[i].Height;
|
||||
ModelData.Add(new Voxel[Width, Length]);
|
||||
Bounds.Add(new Rectangle(new Point(-(int)(Width * Camera.scale) / 2, -(int)(Length * Camera.scale) / 2), new Size((int)(Width * Camera.scale), (int)(Length * Camera.scale))));
|
||||
for (int x = 0; x < LayerImages[i].Width; x++)
|
||||
{
|
||||
for(int y = 0; y < LayerImages[i].Height; y++)
|
||||
@@ -82,20 +208,59 @@ namespace SpriteStacker
|
||||
}
|
||||
}
|
||||
}
|
||||
public void UpdateBounds()
|
||||
{
|
||||
for (int i = 0; i < ModelData.Count; i++)
|
||||
{
|
||||
Bounds[i] = new Rectangle(new Point(-(int)(Width * Camera.scale) / 2, -(int)(Length * Camera.scale) / 2), new Size((int)(Width * Camera.scale), (int)(Length * Camera.scale)));
|
||||
}
|
||||
}
|
||||
public void AddLayer()
|
||||
{
|
||||
LayerImages.Add(new Bitmap(Width, Length));
|
||||
ModelData.Add(new Voxel[Width,Length]);
|
||||
Bounds.Add(new Rectangle(new Point(-(int)(Width * Camera.scale) / 2, -(int)(Length * Camera.scale) / 2), new Size((int)(Width * Camera.scale), (int)(Length * Camera.scale))));
|
||||
}
|
||||
public void DrawSpriteStack(Graphics G)
|
||||
{
|
||||
int X = Camera.LocX + Camera.Width / 2;
|
||||
int Y = Camera.Height / 2 + Camera.LocY;
|
||||
G.ResetTransform();
|
||||
G.TranslateTransform(X, Y);
|
||||
G.RotateTransform(Camera.Rotation);
|
||||
G.FillRectangle(new SolidBrush(Config.BasePlateColour), Bounds[0]);
|
||||
float AngleScale = Camera.ViewAngle * Camera.scale;
|
||||
G.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
G.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
|
||||
for (int i = 0; i < ModelData.Count; i++)
|
||||
{
|
||||
G.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
if (!Camera.EditMode || Camera.EditMode && i != Camera.SelectedLayer)
|
||||
{
|
||||
G.ResetTransform();
|
||||
G.TranslateTransform(X, Y - (i * AngleScale));
|
||||
G.RotateTransform(Camera.Rotation);
|
||||
if (Camera.SelectedLayer == i)
|
||||
{
|
||||
TextureBrush TileBrush = new TextureBrush(Resources.Background);
|
||||
TileBrush.ScaleTransform((1/32.0f) * Camera.scale * (Config.BackgroundTile / 2), (1 / 32.0f) * Camera.scale * (Config.BackgroundTile / 2));
|
||||
G.FillRectangle(TileBrush, Bounds[Camera.SelectedLayer]);
|
||||
G.DrawRectangle(new Pen(Brushes.Black), Bounds[i]);
|
||||
G.DrawRectangle(new Pen(new SolidBrush(Camera.SelectedColor)), new Rectangle(new Point(-(int)(Width * Camera.scale) / 2 + (int)(Camera.BrushX * Camera.scale) - (int)(Math.Floor(Camera.BrushSize / 2.0) * Camera.scale), -(int)(Length * Camera.scale) / 2 + (int)(Camera.BrushY * Camera.scale) - (int)(Math.Floor(Camera.BrushSize / 2.0) * Camera.scale)), new Size((int)(Camera.BrushSize * Camera.scale), (int)(Camera.BrushSize * Camera.scale))));
|
||||
}
|
||||
G.DrawImage(LayerImages[i], Bounds[i]);
|
||||
}
|
||||
}
|
||||
if (Camera.EditMode)
|
||||
{
|
||||
G.ResetTransform();
|
||||
G.TranslateTransform(Camera.LocX + Camera.Width/2,Camera.LocY - (i*Camera.scale) + Camera.Height/2);
|
||||
G.RotateTransform(Camera.Rotation);
|
||||
G.DrawImage(LayerImages[i], new Rectangle(new Point(-(int)(Width * Camera.scale)/2, -(int)(Length * Camera.scale) / 2),new Size((int)(Width * Camera.scale), (int)(Length * Camera.scale))));
|
||||
G.TranslateTransform(X, Y);
|
||||
TextureBrush TileBrush = new TextureBrush(Resources.Background);
|
||||
TileBrush.ScaleTransform((1 / 32.0f) * Camera.scale * (Config.BackgroundTile / 2), (1 / 32.0f) * Camera.scale * (Config.BackgroundTile / 2));
|
||||
G.FillRectangle(TileBrush, Bounds[Camera.SelectedLayer]);
|
||||
G.DrawImage(LayerImages[Camera.SelectedLayer], Bounds[Camera.SelectedLayer]);
|
||||
G.DrawRectangle(new Pen(Brushes.Black), Bounds[Camera.SelectedLayer]);
|
||||
G.DrawRectangle(new Pen(new SolidBrush(Camera.SelectedColor)), new Rectangle(new Point(-(int)(Width * Camera.scale) / 2 + (int)(Camera.BrushX * Camera.scale) - (int)(Math.Floor(Camera.BrushSize / 2.0) * Camera.scale), -(int)(Length * Camera.scale) / 2 + (int)(Camera.BrushY * Camera.scale) - (int)(Math.Floor(Camera.BrushSize / 2.0) * Camera.scale)), new Size((int)(Camera.BrushSize * Camera.scale), (int)(Camera.BrushSize * Camera.scale))));
|
||||
|
||||
}
|
||||
}
|
||||
public void DrawLayersToImages()
|
||||
|
||||
10
SpriteStacker/Properties/Resources.Designer.cs
generated
10
SpriteStacker/Properties/Resources.Designer.cs
generated
@@ -319,5 +319,15 @@ namespace SpriteStacker.Properties {
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap Background {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("Background", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,9 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="Background" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Background.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="_1" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
|
||||
BIN
SpriteStacker/Resources/Background.png
Normal file
BIN
SpriteStacker/Resources/Background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 243 B |
@@ -159,5 +159,8 @@
|
||||
<ItemGroup>
|
||||
<None Include="Resources\16.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\Background.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user