public Bitmap makeObject(int index, ObjRec[] objects, Bitmap[][] objStrips, MapViewType drawType, int constantSubpal = -1) { var obj = objects[index]; int scaleInt16 = 16; var images = new Image[obj.getSize()]; for (int i = 0; i < obj.getSize(); i++) { int x = i % obj.w; int y = i / obj.w; int pali = (y >> 1) * (obj.w >> 1) + (x >> 1); var objStrip = constantSubpal == -1 ? objStrips[obj.getSubpallete(pali)] : objStrips[constantSubpal]; images[i] = objStrip[obj.indexes[i]]; } var mblock = UtilsGDI.GlueImages(images, obj.w, obj.h); using (Graphics g2 = Graphics.FromImage(mblock)) { if (drawType == MapViewType.ObjType) { g2.FillRectangle(new SolidBrush(CadObjectTypeColors[obj.getType()]), new Rectangle(0, 0, scaleInt16, scaleInt16)); g2.DrawString(String.Format("{0:X}", obj.getType()), new Font("Arial", 6), Brushes.White, new Point(0, 0)); } else if (drawType == MapViewType.ObjNumbers) { g2.FillRectangle(new SolidBrush(Color.FromArgb(192, 255, 255, 255)), new Rectangle(0, 0, scaleInt16, scaleInt16)); g2.DrawString(String.Format("{0:X}", index), new Font("Arial", 6), Brushes.Red, new Point(0, 0)); } } return(mblock); }
public Image[] makeBigBlocks(int videoNo, int bigBlockNo, BigBlock[] bigBlockIndexes, int palleteNo, MapViewType smallObjectsViewType = MapViewType.Tiles, MapViewType curViewType = MapViewType.Tiles, int hierarchyLevel = 0) { int blockCount = ConfigScript.getBigBlocksCount(hierarchyLevel); var bigBlocks = new Image[blockCount]; Image[] smallBlocksPack; if (hierarchyLevel == 0) { smallBlocksPack = makeObjects(videoNo, bigBlockNo, palleteNo, smallObjectsViewType); } else { var bigBlockIndexesPrev = ConfigScript.getBigBlocksRecursive(hierarchyLevel - 1, bigBlockNo); smallBlocksPack = makeBigBlocks(videoNo, bigBlockNo, bigBlockIndexesPrev, palleteNo, smallObjectsViewType, curViewType, hierarchyLevel - 1); } //tt version hardcode Image[][] smallBlocksAll = null; bool smallBlockHasSubpals = bigBlockIndexes == null ? true : bigBlockIndexes[0].smallBlocksWithPal(); if (!smallBlockHasSubpals) { smallBlocksAll = new Image[4][]; for (int i = 0; i < 4; i++) { smallBlocksAll[i] = makeObjects(videoNo, bigBlockNo, palleteNo, smallObjectsViewType, i); } } else { smallBlocksAll = new Image[4][] { smallBlocksPack, smallBlocksPack, smallBlocksPack, smallBlocksPack }; } for (int btileId = 0; btileId < blockCount; btileId++) { Image b; if (ConfigScript.isBuildScreenFromSmallBlocks()) { var sb = smallBlocksPack[btileId]; //scale for small blocks b = UtilsGDI.ResizeBitmap(sb, (int)(sb.Width * 2), (int)(sb.Height * 2)); } else { b = bigBlockIndexes[btileId].makeBigBlock(smallBlocksAll); } if (curViewType == MapViewType.ObjNumbers) { b = VideoHelper.addObjNumber(b, btileId); } bigBlocks[btileId] = b; } return(bigBlocks); }
/// <summary> /// Loads Blocks for level editor /// </summary> private void LoadBlocks() { var videoNes = new Video(); var numCols = 5; var currentColumn = 0; var currentRow = 0; _blocks = videoNes.makeBigBlocks(0, 0, 0, 0, MapViewType.Tiles, MapViewType.Tiles, 0); GrdBlocks.Children.Clear(); //loop through blocks and add them to the wrap panel. for (int i = 0; i < _blocks.Length; i++) { var img = new System.Windows.Controls.Image { Stretch = System.Windows.Media.Stretch.Fill, Source = UtilsGDI.GetImageStream(_blocks[i]) }; var border = new Border { BorderBrush = System.Windows.Media.Brushes.White, BorderThickness = new Thickness(1), Child = img }; if (currentColumn == numCols - 1) { //new row var rowDef = new RowDefinition(); GrdBlocks.RowDefinitions.Add(rowDef); GrdBlocks.Children.Add(border); Grid.SetColumn(border, currentColumn); Grid.SetRow(border, currentRow); currentColumn = 0; currentRow++; } else { GrdBlocks.Children.Add(border); Grid.SetColumn(border, currentColumn); Grid.SetRow(border, currentRow); currentColumn++; } } }
/// <summary> /// Loads an 8x8 screen onto the tile map /// </summary> /// <param name="screenNo">The 0 based screen number to load.</param> private void LoadMapScreen(int screenNo, int screenWidth, int screenHeight, bool hasBorder, ref Grid MapGrid) { //int screenWidth = 8; //int screenHeight = 8; int[] screen = _layers[0].screens[screenNo]; int blockNo = 0; //first we need to remove old contents of grid to mitigate memory consumption MapGrid.Children.Clear(); //iterate through block indexes and add appropriate block to map screen for (int i = 0; i < screenHeight; i++) { //for each row for (int y = 0; y < screenWidth; y++) { //for each column var currentBlockIdx = screen[blockNo]; //grab the index of the current block var img = new System.Windows.Controls.Image { Stretch = System.Windows.Media.Stretch.Fill, Source = UtilsGDI.GetImageStream(_blocks[currentBlockIdx]) }; var border = new Border { BorderBrush = System.Windows.Media.Brushes.White, BorderThickness = new Thickness(hasBorder ? 1 : 0), Child = img }; MapGrid.ShowGridLines = false; //add image to map grid MapGrid.Children.Add(border); Grid.SetColumn(border, y); Grid.SetRow(border, i); blockNo++; } } }
public static void RenderAllBlocks(DrawingContext g, System.Windows.Controls.Image parentControl, Image[] bigBlocks, int blockWidth, int blockHeight, Rect?visibleRect, float CurScale, int activeBlock, bool showBlocksAxis) { int TILE_SIZE_X = (int)(blockWidth * CurScale); int TILE_SIZE_Y = (int)(blockHeight * CurScale); int WIDTH = (int)parentControl.Width / TILE_SIZE_X; if (WIDTH == 0) { return; } for (int i = 0; i < bigBlocks.Length; i++) { int bigBlockNo = i; //Rectangle tileRect = new Rectangle((i % WIDTH) * TILE_SIZE_X, i / WIDTH * TILE_SIZE_Y, TILE_SIZE_X, TILE_SIZE_Y); Rect tileRect = new Rect((i % WIDTH) * TILE_SIZE_X, i / WIDTH * TILE_SIZE_Y, TILE_SIZE_X, TILE_SIZE_Y); if (visibleRect == null || visibleRect.Value.Contains(tileRect) || visibleRect.Value.IntersectsWith(tileRect)) { if (bigBlockNo > -1 && bigBlockNo < bigBlocks.Length) { g.DrawImage(UtilsGDI.GetImageStream(bigBlocks[bigBlockNo]), tileRect); } else //g.FillRectangle(System.Windows.Media.Brushes.White, tileRect); if (showBlocksAxis) { g.DrawRectangle(null, new System.Windows.Media.Pen(System.Windows.Media.Brushes.Black, 1), tileRect); //g.DrawRectangle(null,new System.Windows.Media.Pen(Color.FromArgb(255, 255, 255, 255),1), tileRect); } if (i == activeBlock) { //g.DrawRectangle(new Pen(Brushes.Red, 3.0f), tileRect); g.DrawRectangle(null, new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1), tileRect); } } } }
/// <summary> /// replaces the tile on the map screen with the one selected from the block/tile screen /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MapScreen_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { //populate current selected cell with CurrentSelectedBlock //Get currently selected column and row (Note, may refactor later to use Grid.GetRow / Grid.GetColumn ?) var col = GridSelectedColumn(ref MapScreen); var row = GridSelectedRow(ref MapScreen); //navigate to column/row to get cell var cell = MapScreen.Children.Cast <UIElement>() .First(ctl => Grid.GetRow(ctl) == row && Grid.GetColumn(ctl) == col); //I'll eventually rewrite this to use a copy of the layer so it's not rewritten whenever the map is redrawn... if (cell is Border) { var img = new System.Windows.Controls.Image { Stretch = System.Windows.Media.Stretch.Fill, Source = UtilsGDI.GetImageStream(_blocks[CurrentSelectedBlock]) }; ((Border)cell).Child = img; } }
public Bitmap makeObjectsStrip(int videoPageId, int tilesId, int palId, MapViewType drawType, int constantSubpal = -1) { var bitmaps = makeObjects(videoPageId, tilesId, palId, drawType, constantSubpal); return(UtilsGDI.GlueImages(bitmaps, bitmaps.Length, 1)); }
public Bitmap makeImageRectangle(byte[] videoChunk, byte[] pallete, int subPalIndex, bool withAlpha = false) { var images = Enumerable.Range(0, 256).Select(i => makeImage(i, videoChunk, pallete, subPalIndex, withAlpha)); return(UtilsGDI.GlueImages(images.ToArray(), 16, 16)); }