/// <summary> /// On draw backbuffer /// </summary> protected override void OnDrawOnBackbuffer(ref System.Drawing.Graphics gfx) { // If the color matrix is empty, create it if (_cm == null) { _cm = new ColorMatrix(new float[][] { new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }); } // Create new image attributes ImageAttributes ia = new ImageAttributes(); ia.SetColorMatrix(_cm); // Get tile size Size tileSize = _background.TileSize; tileSize.Width += 1; tileSize.Height += 1; // Iterate through instances foreach (GMareInstance inst in App.Room.Blocks) { // Get the object associated with this instance GMareObject obj = App.Room.Objects.Find(delegate(GMareObject o) { return(o.Resource.Id == inst.ObjectId); }); // If no object was found, continue if (obj == null) { continue; } // Get drawing point Point point = GMareBrush.TileIdToSourcePosition(inst.TileId, Image.Width, tileSize); point.X += 1; point.Y += 1; Bitmap image = obj.Image.ToBitmap(); // Draw glyph gfx.DrawImage(image, new Rectangle(point.X, point.Y, obj.Image.Width, obj.Image.Height), 0, 0, obj.Image.Width, obj.Image.Height, GraphicsUnit.Pixel, ia); image.Dispose(); } // Dispose. ia.Dispose(); }
/// <summary> /// Constructs a new brush form /// </summary> /// <param name="background">The background to render from</param> /// <param name="brush">Brush to save</param> /// <param name="tileSize">Size of a single tile</param> public SaveBrushForm(Bitmap background, GMareBrush brush, Size tileSize) { InitializeComponent(); // Create new graphics object Bitmap image = new Bitmap(brush.Width, brush.Height); System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(image); // Iterate through tiles horizontally for (int col = 0; col < brush.Columns; col++) { // Iterate through tiles vertically for (int row = 0; row < brush.Rows; row++) { // If the tile is empty, continue looping if (brush.Tiles[col, row].TileId == -1) { continue; } // Calculate source point Rectangle source = new Rectangle(GMareBrush.TileIdToSourcePosition(brush.Tiles[col, row].TileId, background.Width, tileSize), tileSize); Rectangle dest = new Rectangle(new Point(col * tileSize.Width, row * tileSize.Height), tileSize); // Get tile Bitmap temp = Graphics.PixelMap.PixelDataToBitmap(Graphics.PixelMap.GetPixels(background, source)); Color color = brush.Tiles[col, row].Blend; float red = color.R / 255.0f; float green = color.G / 255.0f; float blue = color.B / 255.0f; // Alpha changing color matrix ColorMatrix cm = new ColorMatrix(new float[][] { new float[] { red, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, green, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, blue, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }); // Create new image attributes ImageAttributes ia = new ImageAttributes(); ia.SetColorMatrix(cm); // Flip tile switch (brush.Tiles[col, row].FlipMode) { case FlipType.Horizontal: temp.RotateFlip(RotateFlipType.RotateNoneFlipX); break; case FlipType.Vertical: temp.RotateFlip(RotateFlipType.RotateNoneFlipY); break; case FlipType.Both: temp.RotateFlip(RotateFlipType.RotateNoneFlipX); temp.RotateFlip(RotateFlipType.RotateNoneFlipY); break; } // Draw tile gfx.DrawImage(temp, dest, 0, 0, tileSize.Width, tileSize.Height, GraphicsUnit.Pixel, ia); // Dispose temp.Dispose(); ia.Dispose(); } } // Set brush image pnlBrush.Image = image; // Dispose of the graphics gfx.Dispose(); // Validate CheckText(); }
/// <summary> /// Gets a string representation of a layer /// </summary> /// <param name="layer">The layer to get tile data from</param> /// <param name="dataType">The type of data to present</param> /// <param name="arrayType">The type of array style to use when writing the string</param> private void SetText(GMareLayer layer, DataType dataType, ArrayType arrayType) { // If no layers, display nothing if (layer == null) { return; } // Clear any existing text txtText.Clear(); // Local variables int index = 0; int roomWidth = 0; if (App.Room.Backgrounds[0].Image != null) { roomWidth = App.Room.Backgrounds[0].Image.Width; } Size roomTileSize = App.Room.Backgrounds[0].TileSize; bool tileData = TilesExist(layer.Tiles); // Create new text StringBuilder text = new StringBuilder(); string layerId = "layer" + layer.Depth.ToString(); layerId = layerId.Replace("-", "_"); // Do action based on array type switch (arrayType) { // If the array present type is a list case ArrayType.List: // Do action based on data type switch (dataType) { // Sector data type case DataType.Sectors: // Create array variable string text.AppendLine(layerId + " = ds_list_create();"); text.AppendLine(); break; // All other data types default: // If there is tile data, create array variable string if (tileData) { text.AppendLine(layerId + " = ds_list_create();"); text.AppendLine(); } break; } break; // If the array present type is a grid case ArrayType.Grid: // If the data type is sectors, create a grid variable if (dataType == DataType.Sectors) { text.AppendLine(layerId + " = ds_grid_create();"); text.AppendLine(); } break; } // Calculate columns and rows int rows = layer.Tiles.GetLength(1); int cols = layer.Tiles.GetLength(0); // Iterate through rows for (int row = 0; row < rows; row++) { // Create a new line StringBuilder line = new StringBuilder(); // Iterate through columns for (int col = 0; col < cols; col++) { // Do action based on data type switch (dataType) { // If sector data must be displayed case DataType.Sectors: // Set sector data text based on desired array type switch (arrayType) { case ArrayType.Raw: line.Append((layer.Tiles[col, row].TileId).ToString() + ", "); break; case ArrayType.Standard: line.Append(layerId + "[" + col + "," + row + "] = " + layer.Tiles[col, row].TileId.ToString() + "; "); break; case ArrayType.List: line.Append("ds_list_add(" + layerId + "," + layer.Tiles[col, row].TileId.ToString() + "); "); break; case ArrayType.Grid: line.Append("ds_grid_add(" + layerId + "," + col + "," + row + "," + layer.Tiles[col, row].TileId.ToString() + "); "); break; } break; // If point data must be displayed case DataType.Points: // If the tile id is -1, don't bother with rectangle data if (layer.Tiles[col, row].TileId == -1) { continue; } // Create a new rectangle that represents the source rectangle Point point = GMareBrush.TileIdToSourcePosition(layer.Tiles[col, row].TileId, roomWidth, roomTileSize); // Set tile data text based on desired array type switch (arrayType) { case ArrayType.Raw: text.AppendLine(new Point(col * roomTileSize.Width, row * roomTileSize.Height).ToString() + " // Destination point."); text.AppendLine(point.ToString() + " // Source Point"); break; case ArrayType.Standard: text.AppendLine(layerId + "[" + index + "] = " + col * roomTileSize.Width + "; " + " // Destination X."); index++; text.AppendLine(layerId + "[" + index + "] = " + row * roomTileSize.Height + "; " + " // Destination Y."); index++; text.AppendLine(layerId + "[" + index + "] = " + point.X + "; " + " // Source X."); index++; text.AppendLine(layerId + "[" + index + "] = " + point.Y + "; " + " // Source Y."); index++; break; case ArrayType.List: text.AppendLine("ds_list_add(" + layerId + ", " + col * roomTileSize.Width + "); " + " // Destination X."); text.AppendLine("ds_list_add(" + layerId + ", " + row * roomTileSize.Height + "); " + " // Destination Y."); text.AppendLine("ds_list_add(" + layerId + ", " + point.X + "); " + " // Source X."); text.AppendLine("ds_list_add(" + layerId + ", " + point.Y + "); " + " // Source Y."); break; } break; // If rectangle data must be displayed case DataType.Rectangles: // If the tile id is -1, don't bother with rectangle data if (layer.Tiles[col, row].TileId == -1) { continue; } // Create a new rectangle that represents the source rectangle Rectangle rect = new Rectangle(); rect.Location = GMareBrush.TileIdToSourcePosition(layer.Tiles[col, row].TileId, roomWidth, roomTileSize); rect.Size = roomTileSize; // Set tile data text based on desired array type switch (arrayType) { case ArrayType.Raw: text.AppendLine(new Point(col * roomTileSize.Width, row * roomTileSize.Height).ToString() + " // Destination point."); text.AppendLine(rect.ToString() + " // Source rectangle."); break; case ArrayType.Standard: text.AppendLine(layerId + "[" + index + "] = " + col * roomTileSize.Width + "; " + " // Destination X."); index++; text.AppendLine(layerId + "[" + index + "] = " + row * roomTileSize.Height + "; " + " // Destination Y."); index++; text.AppendLine(layerId + "[" + index + "] = " + rect.X + "; " + " // Source X."); index++; text.AppendLine(layerId + "[" + index + "] = " + rect.Y + "; " + " // Source Y."); index++; text.AppendLine(layerId + "[" + index + "] = " + rect.Width + "; " + " // Tile Width."); index++; text.AppendLine(layerId + "[" + index + "] = " + rect.Height + "; " + " // Tile Height."); index++; break; case ArrayType.List: text.AppendLine("ds_list_add(" + layerId + "," + col * roomTileSize.Width + "); " + " // Destination X."); text.AppendLine("ds_list_add(" + layerId + "," + row * roomTileSize.Height + "); " + " // Destination Y."); text.AppendLine("ds_list_add(" + layerId + "," + rect.X + "); " + " // Source X."); text.AppendLine("ds_list_add(" + layerId + "," + rect.Y + "); " + " // Source Y."); text.AppendLine("ds_list_add(" + layerId + "," + rect.Width + "); " + " // Tile Width."); text.AppendLine("ds_list_add(" + layerId + "," + rect.Height + "); " + " // Tile Height."); break; } break; } } // Append line to text if (dataType == DataType.Sectors) { text.AppendLine(line.ToString()); } } // Set rich text box text txtText.Text = text.ToString(); }