private void DrawMap(System.Drawing.Image town, IEnumerable <GeoWallRecord> wallRecords, FpViewPos currentFPViewPos) { var surface = Graphics.FromImage(town); surface.Clear(Color.White); DrawGutter(surface); DrawRooms(wallRecords, surface); DrawGrid(surface); DrawViewCursor(surface, currentFPViewPos.cursorX, currentFPViewPos.cursorY, currentFPViewPos.facing); }
/// <summary> /// Render the town map to a bitmap image for rendering onto the surface /// </summary> /// <param name="town"></param> /// <param name="wallRecords"></param> private void Drawfpview(System.Drawing.Image fpview, IEnumerable <GeoWallRecord> wallRecords, FpViewPos currentFPViewPos) { //var surface = Graphics.FromImage(fpview); int eight = 8; int viewPortWidth = (7 * eight) * 2 - (eight * 3); int viewPortHeight = (11 * eight); int xpos = currentFPViewPos.cursorX; int ypos = currentFPViewPos.cursorY; int facing = currentFPViewPos.facing; var cache_bm = new Bitmap(fpview, viewPortWidth, viewPortHeight); var surface = Graphics.FromImage(cache_bm); surface.Clear(Color.White); List <GeoWallRecord> fpsNearMapView = new List <GeoWallRecord>(); List <GeoWallRecord> fpsMidMapView = new List <GeoWallRecord>(); List <GeoWallRecord> fpsFarMapView = new List <GeoWallRecord>(); switch (facing) { case 0: fpsNearMapView = getMapRow(xpos - 1, ypos, xpos + 1, wallRecords); fpsMidMapView = getMapRow(xpos - 2, ypos - 1, xpos + 2, wallRecords); fpsFarMapView = getMapRow(xpos - 3, ypos - 2, xpos + 3, wallRecords); break; case 1: fpsNearMapView = getMapCol(ypos - 1, xpos, ypos + 1, wallRecords); fpsMidMapView = getMapCol(ypos - 2, xpos + 1, ypos + 2, wallRecords); fpsFarMapView = getMapCol(ypos - 3, xpos + 2, ypos + 3, wallRecords); break; case 2: fpsNearMapView = getMapRow(xpos - 1, ypos, xpos + 1, wallRecords); fpsNearMapView.Reverse(); fpsMidMapView = getMapRow(xpos - 2, ypos + 1, xpos + 2, wallRecords); fpsMidMapView.Reverse(); fpsFarMapView = getMapRow(xpos - 3, ypos + 2, xpos + 3, wallRecords); fpsFarMapView.Reverse(); break; case 3: fpsNearMapView = getMapCol(ypos - 1, xpos, ypos + 1, wallRecords); fpsNearMapView.Reverse(); fpsMidMapView = getMapCol(ypos - 2, xpos - 1, ypos + 2, wallRecords); fpsMidMapView.Reverse(); fpsFarMapView = getMapCol(ypos - 3, xpos - 2, ypos + 3, wallRecords); fpsFarMapView.Reverse(); break; } var c = 0; int lastWall = 0; int lastRightWall = 0; foreach (var w in fpsFarMapView) { var wallType = getOppositeWall(w, facing); if (wallType > 0) { DrawFarFacingWall(surface, c, 8, w.Event & 127, wallType); if (c <= 3 && c > 0) { if (getLeftWall(w, facing) > 0 || lastWall > 0) { DrawFarFacingWallAdj(surface, c, 8, w.Event & 127, wallType); } } } if (c > 3 && lastWall > 0) { if (wallType > 0 || lastRightWall > 0) { DrawFarFacingWallAdj(surface, c, 8, w.Event & 127, lastWall); } } c++; lastWall = wallType; lastRightWall = getRightWall(w, facing); } c = 0; foreach (var w in fpsFarMapView) { if (c > 0 && c < 6) { var wallType = getRightWall(w, facing); if (c >= 3) { if (wallType > 0) { DrawFarRightWall(surface, c, 8, w.Event & 127, wallType); } } wallType = getLeftWall(w, facing); if (c <= 3) { if (wallType > 0) { DrawFarLeftWall(surface, c, 8, w.Event & 127, wallType); } } } c++; } c = 0; foreach (var w in fpsMidMapView) { var wallType = getOppositeWall(w, facing); if (wallType > 0) { DrawMidFacingWall(surface, c, 8, w.Event & 127, wallType); } c++; } c = 0; foreach (var w in fpsMidMapView) { if (c > 0 && c < 5) { var wallType = getLeftWall(w, facing); if (wallType > 0 && c < 3) { DrawMidLeftWall(surface, c, 8, w.Event & 127, wallType); } wallType = getRightWall(w, facing); if (wallType > 0 && c > 1) { DrawMidRightWall(surface, c, 8, w.Event & 127, wallType); } } c++; } c = 0; foreach (var w in fpsNearMapView) { var wallType = getOppositeWall(w, facing); if (wallType > 0) { DrawNearFacingWall(surface, c, 8, w.Event & 127, wallType); } c++; } c = 0; foreach (var w in fpsNearMapView) { if (c == 1) { var wallType = getRightWall(w, facing); if (wallType > 0) { DrawNearRightWall(surface, c, 8, w.Event & 127, wallType); } wallType = getLeftWall(w, facing); if (wallType > 0) { DrawNearLeftWall(surface, c, 8, w.Event & 127, wallType); } } c++; } DrawViewPort(surface, c, 8, 127); var screenSurface = Graphics.FromImage(fpview); var r = new Rectangle(0, 0, viewPortWidth * 4, viewPortHeight * 4); screenSurface.DrawImage(cache_bm, r); }
public Control GetControl() { var maps = _goldBoxFile.GetMaps(); tab = new TabControl { Dock = DockStyle.Fill }; tab.Invalidated += InvalidateMap; foreach (var geoMapRecord in maps) { var newFPViewPos = new FpViewPos(); selected_dax_id = geoMapRecord.DaxId; var page = new TabPage(geoMapRecord.Name) { Size = new Size(FullMapWidth + FPViewWidth, Math.Max(FPViewHeight, FullMapHeight)) }; page.Tag = newFPViewPos; var panel = ViewerHelper.CreatePanel(); panel.Name = "mapPanel"; var exportButton = ViewerHelper.CreateButton(); exportButton.Text = "export map to image"; exportButton.MouseClick += geoImageExportForm; var movementButtonPanel = ViewerHelper.CreatePanel(); movementButtonPanel.Width = 50; movementButtonPanel.Name = "Movement Button Panel"; movementButtonPanel.Dock = DockStyle.Bottom; var forwardButton = ViewerHelper.CreateButton(); forwardButton.Text = "Forward"; forwardButton.Width = 40; forwardButton.MouseClick += moveCursorForwards; forwardButton.Dock = DockStyle.Top; var movementRow3 = ViewerHelper.CreateRow(); movementRow3.Controls.Add(forwardButton); var backwardButton = ViewerHelper.CreateButton(); backwardButton.Text = "Back"; backwardButton.Width = 40; backwardButton.MouseClick += moveCursorBackwards; backwardButton.Dock = DockStyle.Bottom; var movementRow1 = ViewerHelper.CreateRow(); movementRow1.Controls.Add(backwardButton); var leftButton = ViewerHelper.CreateButton(); leftButton.Text = "Left"; backwardButton.Width = 40; leftButton.MouseClick += rotateCursorLeft; leftButton.Dock = DockStyle.Left; var rightButton = ViewerHelper.CreateButton(); rightButton.Text = "Right"; rightButton.Width = 40; rightButton.MouseClick += rotateCursorRight; rightButton.Dock = DockStyle.Fill; var movementRow2 = ViewerHelper.CreateRow(); movementRow2.Controls.Add(rightButton); movementRow2.Controls.Add(leftButton); var fpViewPanel = ViewerHelper.CreatePanel(); fpViewPanel.Dock = DockStyle.Left; fpViewPanel.Width = FPViewWidth; fpViewPanel.Height = FPViewHeight; fpViewPanel.Name = "FPViewPanel"; // var mapPanel = ViewerHelper.CreatePanel(); var fpViewBox = new PictureBox(); fpViewBox.Dock = DockStyle.Fill; fpViewBox.BorderStyle = BorderStyle.Fixed3D; var pictureBox = new PictureBox(); pictureBox.Dock = DockStyle.Left; pictureBox.MouseClick += mouseClickOnMap; movementButtonPanel.Controls.Add(movementRow1); movementButtonPanel.Controls.Add(movementRow2); movementButtonPanel.Controls.Add(movementRow3); var bitmap = new Bitmap(FullMapWidth, FullMapHeight); DrawMap(bitmap, geoMapRecord.Walls, newFPViewPos); pictureBox.Name = "map"; pictureBox.Image = bitmap; pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Size = new Size(FullMapWidth, FullMapHeight); var fpvbitmap = new Bitmap(FPViewWidth, FPViewHeight); Drawfpview(fpvbitmap, geoMapRecord.Walls, newFPViewPos); fpViewBox.Name = "3d view"; fpViewBox.Image = fpvbitmap; fpViewBox.SizeMode = PictureBoxSizeMode.Zoom; fpViewBox.Size = new Size(FPViewWidth, FPViewHeight + 60); fpViewPanel.Controls.Add(fpViewBox); fpViewPanel.Controls.Add(movementButtonPanel); panel.Controls.Add(fpViewPanel); panel.Controls.Add(pictureBox); panel.Controls.Add(exportButton); page.AutoScroll = true; page.Controls.Add(panel); tab.TabPages.Add(page); } return(tab); }
private void DrawMap(System.Drawing.Image town, IEnumerable<GeoWallRecord> wallRecords, FpViewPos currentFPViewPos) { var surface = Graphics.FromImage(town); surface.Clear(Color.White); DrawGutter(surface); DrawRooms(wallRecords, surface); DrawGrid(surface); DrawViewCursor(surface, currentFPViewPos.cursorX, currentFPViewPos.cursorY, currentFPViewPos.facing); }
/// <summary> /// Render the town map to a bitmap image for rendering onto the surface /// </summary> /// <param name="town"></param> /// <param name="wallRecords"></param> private void Drawfpview(System.Drawing.Image fpview, IEnumerable<GeoWallRecord> wallRecords, FpViewPos currentFPViewPos) { //var surface = Graphics.FromImage(fpview); int eight = 8; int viewPortWidth = (7 * eight)* 2 - (eight*3) ; int viewPortHeight = (11 * eight); int xpos = currentFPViewPos.cursorX; int ypos = currentFPViewPos.cursorY; string facing = currentFPViewPos.facing; var cache_bm = new Bitmap(fpview, viewPortWidth, viewPortHeight); var surface = Graphics.FromImage(cache_bm); surface.Clear(Color.White); // surface. // var xpos = cursorX; // var ypos = cursorY; List<GeoWallRecord> fpsNearMapView = new List<GeoWallRecord>(); List<GeoWallRecord> fpsMidMapView = new List<GeoWallRecord>(); List<GeoWallRecord> fpsFarMapView = new List<GeoWallRecord>(); if (facing == "s") { fpsNearMapView = getMapRow(xpos - 1, ypos, xpos + 1, wallRecords); fpsNearMapView.Reverse(); fpsMidMapView = getMapRow(xpos - 2, ypos + 1, xpos + 2, wallRecords); fpsMidMapView.Reverse(); fpsFarMapView = getMapRow(xpos - 3, ypos + 2, xpos + 3, wallRecords); fpsFarMapView.Reverse(); } if (facing == "n") { fpsNearMapView = getMapRow(xpos - 1, ypos, xpos + 1, wallRecords); fpsMidMapView = getMapRow(xpos - 2, ypos - 1, xpos + 2, wallRecords); fpsFarMapView = getMapRow(xpos - 3, ypos - 2, xpos + 3, wallRecords); } if (facing == "e") { fpsNearMapView = getMapCol(ypos - 1, xpos, ypos + 1, wallRecords); fpsMidMapView = getMapCol(ypos - 2, xpos + 1, ypos + 2, wallRecords); fpsFarMapView = getMapCol(ypos - 3, xpos + 2, ypos + 3, wallRecords); } if (facing == "w") { fpsNearMapView = getMapCol(ypos - 1, xpos, ypos + 1, wallRecords); fpsNearMapView.Reverse(); fpsMidMapView = getMapCol(ypos - 2, xpos - 1, ypos + 2, wallRecords); fpsMidMapView.Reverse(); fpsFarMapView = getMapCol(ypos - 3, xpos - 2, ypos + 3, wallRecords); fpsFarMapView.Reverse(); } var c = 0; int lastWall = 0; int lastRightWall = 0; foreach (var w in fpsFarMapView) { var wallType = getOppositeWall(w, facing); if (wallType > 0) { DrawFarFacingWall(surface, c, 8, w.Event & 127, wallType); if (c <= 3 && c > 0) { if (getLeftWall(w, facing) > 0 || lastWall > 0) { DrawFarFacingWallAdj(surface, c, 8, w.Event & 127, wallType); } } } if (c > 3 && lastWall > 0) { if (wallType > 0 || lastRightWall > 0) { DrawFarFacingWallAdj(surface, c, 8, w.Event & 127, lastWall); } } c++; lastWall = wallType; lastRightWall = getRightWall(w, facing); } c = 0; foreach (var w in fpsFarMapView) { if (c > 0 && c < 6) { var wallType = getRightWall(w, facing); if (c >= 3) { if (wallType > 0) DrawFarRightWall(surface, c, 8, w.Event & 127, wallType); } wallType = getLeftWall(w, facing); if (c <= 3) { if (wallType > 0) DrawFarLeftWall(surface, c, 8, w.Event & 127, wallType); } } c++; } c = 0; foreach (var w in fpsMidMapView) { var wallType = getOppositeWall(w, facing); if (wallType > 0) DrawMidFacingWall(surface, c, 8, w.Event & 127, wallType); c++; } c = 0; foreach (var w in fpsMidMapView) { if (c > 0 && c < 5) { var wallType = getLeftWall(w, facing); if (wallType > 0 && c < 3) DrawMidLeftWall(surface, c, 8, w.Event & 127, wallType); wallType = getRightWall(w, facing); if (wallType > 0 && c > 1) DrawMidRightWall(surface, c, 8, w.Event & 127, wallType); } c++; } c = 0; foreach (var w in fpsNearMapView) { var wallType = getOppositeWall(w, facing); if (wallType > 0) DrawNearFacingWall(surface, c, 8, w.Event & 127, wallType); c++; } c = 0; foreach (var w in fpsNearMapView) { if (c == 1) { var wallType = getRightWall(w, facing); if (wallType > 0) DrawNearRightWall(surface, c, 8, w.Event & 127, wallType); wallType = getLeftWall(w, facing); if (wallType > 0) DrawNearLeftWall(surface, c, 8, w.Event & 127, wallType); } c++; } DrawViewPort(surface, c, 8, 127); var screenSurface = Graphics.FromImage(fpview); var r =new Rectangle(0, 0, viewPortWidth*4, viewPortHeight*4); screenSurface.DrawImage(cache_bm, r); }
public Control GetControl() { var maps = _goldBoxFile.GetMaps(); tab = new TabControl {Dock = DockStyle.Fill}; tab.Invalidated += InvalidateMap; foreach (var geoMapRecord in maps) { var newFPViewPos = new FpViewPos(); //System.Diagnostics.Debug.WriteLine("name='"+ geoMapRecord.Name+"'"); //mapCursors.Add(geoMapRecord.DaxId, newFPViewPos); selected_dax_id = geoMapRecord.DaxId; var page = new TabPage(geoMapRecord.Name) {Size = new Size(FullMapWidth + FPViewWidth, Math.Max(FPViewHeight, FullMapHeight))}; page.Tag = newFPViewPos; var panel = ViewerHelper.CreatePanel(); panel.Name = "mapPanel"; var exportButton = ViewerHelper.CreateButton(); exportButton.Text = "export map to image"; exportButton.MouseClick += geoImageExportForm; var movementButtonPanel = ViewerHelper.CreatePanel(); movementButtonPanel.Width = 50; movementButtonPanel.Name = "Movement Button Panel"; movementButtonPanel.Dock = DockStyle.Bottom; var forwardButton = ViewerHelper.CreateButton(); forwardButton.Text = "Forward"; forwardButton.Width = 40; forwardButton.MouseClick += moveCursorForwards; forwardButton.Dock = DockStyle.Top; var movementRow3 = ViewerHelper.CreateRow(); movementRow3.Controls.Add(forwardButton); var backwardButton = ViewerHelper.CreateButton(); backwardButton.Text = "Back"; backwardButton.Width = 40; backwardButton.MouseClick += moveCursorBackwards; backwardButton.Dock = DockStyle.Bottom; var movementRow1 = ViewerHelper.CreateRow(); movementRow1.Controls.Add(backwardButton); var leftButton = ViewerHelper.CreateButton(); leftButton.Text = "Left"; backwardButton.Width = 40; leftButton.MouseClick += rotateCursorLeft; leftButton.Dock = DockStyle.Left; var rightButton = ViewerHelper.CreateButton(); rightButton.Text = "Right"; rightButton.Width = 40; rightButton.MouseClick += rotateCursorRight; rightButton.Dock = DockStyle.Fill; var movementRow2 = ViewerHelper.CreateRow(); movementRow2.Controls.Add(rightButton); movementRow2.Controls.Add(leftButton); var fpViewPanel = ViewerHelper.CreatePanel(); fpViewPanel.Dock = DockStyle.Left; fpViewPanel.Width = FPViewWidth; fpViewPanel.Height = FPViewHeight; fpViewPanel.Name = "FPViewPanel"; // var mapPanel = ViewerHelper.CreatePanel(); var fpViewBox = new PictureBox(); fpViewBox.Dock = DockStyle.Fill; fpViewBox.BorderStyle = BorderStyle.Fixed3D; var pictureBox = new PictureBox(); pictureBox.Dock = DockStyle.Left ; pictureBox.MouseClick += mouseClickOnMap; movementButtonPanel.Controls.Add(movementRow1); movementButtonPanel.Controls.Add(movementRow2); movementButtonPanel.Controls.Add(movementRow3); var bitmap = new Bitmap(FullMapWidth, FullMapHeight); DrawMap(bitmap, geoMapRecord.Walls, newFPViewPos); pictureBox.Name = "map"; pictureBox.Image = bitmap; pictureBox.SizeMode = PictureBoxSizeMode.Zoom; pictureBox.Size = new Size(FullMapWidth, FullMapHeight); var fpvbitmap = new Bitmap(FPViewWidth, FPViewHeight); Drawfpview(fpvbitmap, geoMapRecord.Walls, newFPViewPos); fpViewBox.Name = "3d view"; fpViewBox.Image = fpvbitmap; fpViewBox.SizeMode = PictureBoxSizeMode.Zoom; fpViewBox.Size = new Size(FPViewWidth, FPViewHeight+60); fpViewPanel.Controls.Add(fpViewBox); fpViewPanel.Controls.Add(movementButtonPanel); panel.Controls.Add(fpViewPanel); panel.Controls.Add(pictureBox); panel.Controls.Add(exportButton); page.AutoScroll = true; page.Controls.Add(panel); tab.TabPages.Add(page); } return tab; }