public void OnTemplateChanged(TemplateDoc tmpd, string strProperty, string strName, string strParam) { if (TemplateChanged != null) { TemplateChanged(tmpd, strProperty, strName, strParam); } }
void TemplateDocTemplate_TemplateChanged(TemplateDoc tmpd, string strProperty, string strName, string strParam) { if (tmpd == this) { SetModified(true); } }
public Tile(SerializationInfo info, StreamingContext ctx) : base(info, ctx) { m_strName = null; try { m_strName = info.GetString("Name"); } catch { m_strName = info.GetInt32("Cookie").ToString(); } m_afVisible = (bool[, ])info.GetValue("Visibility", typeof(bool[, ])); try { m_afOccupancy = (bool[, ])info.GetValue("Occupancy", typeof(bool[, ])); } catch { TemplateDoc tmpd = (TemplateDoc)DocManager.GetActiveDocument(typeof(TemplateDoc)); Template tmpl = tmpd.FindTemplate(m_strName); if (tmpl != null) { m_afOccupancy = tmpl.OccupancyMap; } else { m_afOccupancy = new bool[1, 1]; } } InitCommon(); }
void TemplateDocTemplate_TemplateChanged(TemplateDoc tmpd, string strProperty, string strName, string strParam) { if (m_strName != strName) { return; } // Flush cached items GetTemplate(null); // Handle changes switch (strProperty) { case "Name": m_strName = strParam; OnPropertyChanged(this, "Name"); break; case "Bitmap": OnPropertyChanged(this, "Bitmap"); break; } }
public EditTerrainForm(TemplateDoc tmpd) { // // Required for Windows Form Designer support // InitializeComponent(); m_sizTile = tmpd.TileSize; for (int n = 0; n < m_abr.Length; n++) { m_abr[n] = new SolidBrush(s_aclrTerrain[n]); } Template[] atmpl = tmpd.GetTemplates(); panel1.SuspendLayout(); foreach (Template tmpl in atmpl) { PictureBox picb = new PictureBox(); picb.Image = ConstructTerrainBitmap(tmpl); picb.SizeMode = PictureBoxSizeMode.AutoSize; picb.Tag = (Object)tmpl; picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown); panel1.Controls.Add(picb); } panel1.ResumeLayout(); }
public void OnTemplatesRemoved(TemplateDoc tmpd, string[] astrName) { if (TemplatesRemoved != null) { TemplatesRemoved(tmpd, astrName); } }
public override void Draw(Graphics g, int x, int y, Size sizTile, TemplateDoc tmpd, LayerType layer, bool fSelected) { if (layer == LayerType.Area) { DrawArea(g, x, y, sizTile, fSelected); } }
private void menuItemScaleDown_Click(object sender, System.EventArgs e) { // If no template doc active, bail if (m_tmpdActive == null) { return; } // Make sure 24 x 24 (could actually allow any sort of conversion...) if (m_tmpdActive.TileSize.Width != 24 && m_tmpdActive.TileSize.Height != 24) { MessageBox.Show(DocManager.GetFrameParent(), "The current template collection must be 24 x 24 tile size"); return; } // Get busy TemplateDoc tmpdDst = TemplateTools.CloneTemplateDoc(m_tmpdActive); TemplateTools.ScaleTemplates(tmpdDst, new Size(16, 16)); TemplateTools.QuantizeTemplates(tmpdDst, null, 0, 0, 0); DocManager.SetActiveDocument(typeof(TemplateDoc), tmpdDst); }
public Template(TemplateDoc doc, Bitmap bm, string strName) { m_strName = strName; Doc = doc; if (!SetBitmap(bm)) throw new Exception("Invalid tile template"); }
private void comboDocs_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if (e.Index < 0 || e.Index >= comboDocs.Items.Count) { return; } string strName; if (e.Index == 0) { Document docActive = DocManager.GetActiveDocument(typeof(TemplateDoc)); if (docActive == null) { strName = "None"; } else { strName = "Active (" + docActive.GetName() + ")"; } m_tmpdCurrent = null; } else { Document doc = (Document)comboDocs.Items[e.Index]; m_tmpdCurrent = (TemplateDoc)doc; strName = doc.GetName(); } e.DrawBackground(); e.Graphics.DrawString(strName, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y); e.DrawFocusRectangle(); }
public static Template ConstructTemplate(TemplateDoc tmpd, MixTemplate mixt, Size sizTile) { Bitmap bm = new Bitmap(mixt.XTileCount * sizTile.Width, mixt.YTileCount * sizTile.Height); Graphics g = Graphics.FromImage(bm); g.Clear(Color.FromArgb(255, 0, 255)); Bitmap bmNew = new Bitmap(sizTile.Width, sizTile.Height, PixelFormat.Format24bppRgb); Graphics gNew = Graphics.FromImage(bmNew); for (int tx = 0; tx < mixt.XTileCount; tx++) { for (int ty = 0; ty < mixt.YTileCount; ty++) { Bitmap bmT = mixt.TileBitmaps[tx + ty * mixt.XTileCount]; if (bmT == null) { continue; } gNew.DrawImage(bmT, 0, 0, sizTile.Width, sizTile.Height); g.DrawImageUnscaled(bmNew, tx * sizTile.Width, ty * sizTile.Height, sizTile.Width, sizTile.Height); } } gNew.Dispose(); bmNew.Dispose(); g.Dispose(); bm.RotateFlip(RotateFlipType.RotateNoneFlipX); return(new Template(tmpd, bm, mixt.Index.ToString())); }
public static void MakePalette(string[] astr) { // -makepal 16 templates.tc palsize fixpalsize backgroundpalsize fixed.pal out.pal // tile size Size sizTile = new Size(0, 0); sizTile.Width = int.Parse(astr[1]); sizTile.Height = sizTile.Width; // Load template collection TemplateDoc tmpd = (TemplateDoc)DocManager.OpenDocument(astr[2]); // palette size int cPalEntries = int.Parse(astr[3]); // entries fixed int cPalEntriesFixed = int.Parse(astr[4]); // entries for background int cPalEntriesBackground = int.Parse(astr[5]); // fixed palette Palette palFixed = new Palette(astr[6]); // output palette string strFilePalOut = astr[7]; // If this template collection already has a palette it has already been quantized; we don't // want that. if (tmpd.GetPalette() != null) { new Exception("Template collection has already been quantized!"); } // Scale templates if needed if (sizTile.Width != tmpd.TileSize.Width || sizTile.Height != tmpd.TileSize.Height) { TemplateTools.ScaleTemplates(tmpd, sizTile); } // Quantize TemplateTools.QuantizeTemplates(tmpd, palFixed, cPalEntries, cPalEntriesFixed, cPalEntriesBackground); // Save the new palette out Palette palNew = tmpd.GetPalette(); palNew.SaveJasc(strFilePalOut); }
void SetActiveDoc(TemplateDoc tmpd) { if (tmpd == m_tmpdActive) { return; } if (tmpd == null) { flowPanel.Controls.Clear(); } else { ComboItem ciFound = null; for (int nIndex = 0; nIndex < comboDocs.Items.Count; nIndex++) { ComboItem ci = (ComboItem)comboDocs.Items[nIndex]; if (ci.m_tmpd == tmpd) { ciFound = ci; comboDocs.SelectedIndex = nIndex; break; } } if (ciFound != null) { FillPanel(ciFound.m_alsPictureBoxes); } } m_tmpdActive = tmpd; }
public TileSet(TemplateDoc tmpd, string strFile) { TemplateDoc = tmpd; m_pal = tmpd.GetPalette(); m_sizTile = tmpd.TileSize; FileName = strFile.Replace(".tc", ".tset"); SuckTemplates(); }
public override Bitmap GetBitmap(Size sizTile, TemplateDoc tmpd) { Bitmap bm = new Bitmap(sizTile.Width * m_ctx, sizTile.Height * m_cty); Graphics g = Graphics.FromImage(bm); DrawArea(g, 0, 0, sizTile, false); g.Dispose(); return(bm); }
public Template(TemplateDoc doc, Bitmap bm, string strName) { m_strName = strName; Doc = doc; if (!SetBitmap(bm)) { throw new Exception("Invalid tile template"); } }
PictureBox CreatePictureBox(TemplateDoc tmpd, Size sizTile, IMapItem mi) { PictureBox picb = new PictureBox(); picb.Image = Misc.TraceEdges(mi.GetBitmap(sizTile, tmpd), 1, Color.Azure); picb.SizeMode = PictureBoxSizeMode.AutoSize; picb.Tag = (Object)mi; picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown); return(picb); }
ComboItem FindComboItem(TemplateDoc tmpd) { int nIndex = FindComboIndex(tmpd); if (nIndex == -1) { return(null); } return((ComboItem)comboDocs.Items[nIndex]); }
Size GetTileSize() { TemplateDoc tmpd = GetTemplateDoc(); if (tmpd == null) { return(new Size(24, 24)); } return(tmpd.TileSize); }
public override Rectangle GetBoundingRectAt(int x, int y, Size sizTile, TemplateDoc tmpd) { Point ptTOrigin = GetTileOrigin(sizTile); Point ptGobOrigin = m_gimg.GetOrigin(sizTile); int xT = x + ptTOrigin.X - ptGobOrigin.X; int yT = y + ptTOrigin.Y - ptGobOrigin.Y; Size siz = GetSize(sizTile); return(new Rectangle(xT, yT, siz.Width, siz.Height)); }
public Tile(TemplateDoc tmpd, string strName, int tx, int ty) { m_strName = strName; m_tx = tx; m_ty = ty; Template tmpl = GetTemplate(tmpd); m_afOccupancy = tmpl.OccupancyMap; m_afVisible = null; InitCommon(); }
public TileSet(TemplateDoc tmpd, string strFile, string strFilePal, int nDepth, Size sizTile) { TemplateDoc = tmpd; m_pal = new Palette(strFilePal + "_" + nDepth.ToString() + "bpp.pal"); TileCollectionFileName = strFile; FileName = strFile.Replace(".tc", ".tset"); PalBinFileName = Path.GetFileName(strFilePal) + ".palbin"; m_sizTile = sizTile; SuckTemplates(); }
private void LevelView_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { Point ptMouse = ViewToWorld(new Point(e.X - AutoScrollPosition.X, e.Y - AutoScrollPosition.Y)); TemplateDoc tmpd = GetTemplateDoc(); Size sizTile = GetTileSize(); // Update status bar int tx = ptMouse.X / sizTile.Width; int ty = ptMouse.Y / sizTile.Height; Globals.StatusBar.Text = String.Format("Coords: {0}, {1}", tx, ty); // If we're dragging a selection, handle it here if (m_fDragSelect) { DragSelectExtend(e); return; } // Send input to MapItem, see if it wants it IMapItem mi = m_miCapturedMouse; if (mi == null) { mi = m_lvld.HitTest(ptMouse.X, ptMouse.Y, sizTile, tmpd, m_lyrf); } if (mi != null) { if (mi.OnMouseMove(e, ptMouse, sizTile, tmpd)) { return; } } // We're not extending a selection. Perhaps we're initiating a drag drop operation // Check initiation conditions if (m_lvld.Selection.Count == 0) { return; } if (MouseButtons != MouseButtons.Left) { return; } if (m_rcDragStart.Contains(ptMouse.X, ptMouse.Y)) { return; } PerformDragDrop(e, m_ptMouseDown); }
private void menuItemQuantizeOnly_Click(object sender, System.EventArgs e) { if (m_tmpdActive == null) { return; } TemplateDoc tmpdDst = TemplateTools.CloneTemplateDoc(m_tmpdActive); TemplateTools.QuantizeTemplates(tmpdDst, null, 0, 0, 0); DocManager.SetActiveDocument(typeof(TemplateDoc), tmpdDst); }
int FindComboIndex(TemplateDoc tmpd) { for (int nIndex = 0; nIndex < comboDocs.Items.Count; nIndex++) { ComboItem ci = (ComboItem)comboDocs.Items[nIndex]; if (ci.m_tmpd == tmpd) { return(nIndex); } } return(-1); }
public override bool HitTest(int x, int y, Size sizTile, TemplateDoc tmpd) { int xT = x - (int)m_tx * sizTile.Width; int yT = y - (int)m_ty * sizTile.Height; Size sizT = new Size(sizTile.Width * m_ctx, sizTile.Height * m_cty); if (xT >= 0 && xT < sizT.Width && yT >= 0 && yT < sizT.Height) { return(true); } return(false); }
public override bool HitTest(int x, int y, Size sizTile, TemplateDoc tmpd) { int xT = x - (int)m_tx * sizTile.Width; int yT = y - (int)m_ty * sizTile.Height; Size sizGob = m_gimg.GetSize(sizTile); if (xT > 0 && xT < sizGob.Width && yT > 0 && yT < sizGob.Height) { Bitmap[] abm = m_gimg.GetBitmapSides(sizTile); return(abm[0].GetPixel(xT, yT) != Color.Transparent); } return(false); }
private Rectangle GetBoundingRect(IMapItem[] ami) { Rectangle rc = new Rectangle(); TemplateDoc tmpd = GetTemplateDoc(); Size sizTile = GetTileSize(); foreach (IMapItem mi in ami) { int x = (int)(mi.tx * sizTile.Width); int y = (int)(mi.ty * sizTile.Height); rc = UnionRect(rc, mi.GetBoundingRectAt(x, y, sizTile, tmpd)); } return(rc); }
void TemplateDocTemplate_DocRemoved(Document doc) { TemplateDoc tmpd = (TemplateDoc)doc; tmpd.ModifiedChanged -= new TemplateDoc.ModifiedChangedHandler(TemplateDoc_ModifiedChanged); tmpd.NameChanged -= new TemplateDoc.NameChangedHandler(TemplateDoc_NameChanged); ComboItem ci = FindComboItem((TemplateDoc)doc); if (ci != null) { comboDocs.Items.Remove(ci); } toolTip.RemoveAll(); }
void TemplateDocTemplate_TemplatesAdded(TemplateDoc tmpd, string[] astrNames) { ComboItem ci = FindComboItem(tmpd); foreach (string strName in astrNames) { PictureBox picb = CreatePictureBox(tmpd, tmpd.TileSize, new Tile(tmpd, strName, 0, 0)); ci.m_alsPictureBoxes.Add(picb); toolTip.SetToolTip(picb, strName); } if (tmpd == m_tmpdActive) { FillPanel(ci.m_alsPictureBoxes); } }
public override void Draw(Graphics g, int x, int y, Size sizTile, TemplateDoc tmpd, LayerType layer, bool fSelected) { if (layer == LayerType.Galaxite) { Bitmap[] abm = m_gimg.GetBitmapSides(sizTile); Bitmap bm = abm[0]; if (fSelected) { Rectangle rcDst = new Rectangle(x, y, bm.Width, bm.Height); ImageAttributes attr = new ImageAttributes(); attr.SetGamma(0.5f); g.DrawImage(bm, rcDst, 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel, attr); } else { g.DrawImage(bm, x, y); } } }
public override bool HitTest(int x, int y, Size sizTile, TemplateDoc tmpd) { Point ptTOrigin = GetTileOrigin(sizTile); Point ptGobOrigin = m_gimg.GetOrigin(sizTile); Size sizGob = m_gimg.GetSize(sizTile); int xT = x - ((int)m_tx * sizTile.Width + ptTOrigin.X - ptGobOrigin.X); int yT = y - ((int)m_ty * sizTile.Height + ptTOrigin.Y - ptGobOrigin.Y); if (xT > 0 && xT < sizGob.Width && yT > 0 && yT < sizGob.Height) { Bitmap[] abmGob = m_gimg.GetBitmapSides(sizTile); return(abmGob[(int)m_side].GetPixel(xT, yT) != Color.Transparent); } return(false); }
public EditTerrainForm(TemplateDoc tmpd) { // // Required for Windows Form Designer support // InitializeComponent(); m_sizTile = tmpd.TileSize; for (int n = 0; n < m_abr.Length; n++) m_abr[n] = new SolidBrush(s_aclrTerrain[n]); Template[] atmpl = tmpd.GetTemplates(); panel1.SuspendLayout(); foreach (Template tmpl in atmpl) { PictureBox picb = new PictureBox(); picb.Image = ConstructTerrainBitmap(tmpl); picb.SizeMode = PictureBoxSizeMode.AutoSize; picb.Tag = (Object)tmpl; picb.MouseDown += new MouseEventHandler(PictureBox_MouseDown); panel1.Controls.Add(picb); } panel1.ResumeLayout(); }
void TemplateDocTemplate_DocRemoved(Document doc) { // We'll get notified of this after the window has been destroyed. Only // handle this event if this isn't the case if (!Created) return; if (m_tmpdCurrent == (TemplateDoc)doc) { m_tmpdCurrent = null; comboDocs.SelectedIndex = 0; } comboDocs.Items.Remove(doc); }
private void comboDocs_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if (e.Index < 0 || e.Index >= comboDocs.Items.Count) return; string strName; if (e.Index == 0) { Document docActive = DocManager.GetActiveDocument(typeof(TemplateDoc)); if (docActive == null) { strName = "None"; } else { strName = "Active (" + docActive.GetName() + ")"; } m_tmpdCurrent = null; } else { Document doc = (Document)comboDocs.Items[e.Index]; m_tmpdCurrent = (TemplateDoc)doc; strName = doc.GetName(); } e.DrawBackground(); e.Graphics.DrawString(strName, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y); e.DrawFocusRectangle(); }
public static void ScaleTemplates(TemplateDoc tmpd, Size sizTile) { // Scale templates Template[] atmpl = tmpd.GetTemplates(); Template tmplBackground = tmpd.GetBackgroundTemplate(); tmpd.RemoveTemplates(atmpl); foreach (Template tmpl in atmpl) ScaleTemplate(tmpl, tmpd.TileSize, sizTile); tmpd.TileSize = sizTile; tmpd.AddTemplates(atmpl); tmpd.SetBackgroundTemplate(tmplBackground); }
public void DrawTileMap(Bitmap bm, ArrayList alsmiSelected, Size sizTile, TemplateDoc tmpd, LayerFlags lyrf) { // Draw background using (Graphics g = Graphics.FromImage(bm)) { Template tmplBackground = null; if (tmpd != null) tmplBackground = tmpd.GetBackgroundTemplate(); if (tmplBackground == null) { g.FillRectangle(new SolidBrush(Color.Black), 0, 0, bm.Width, bm.Height); for (int x = sizTile.Width; x < bm.Width; x += sizTile.Width) { for (int y = sizTile.Height; y < bm.Height; y += sizTile.Height) { bm.SetPixel(x, y, Color.BlanchedAlmond); } } } else { for (int x = 0; x < bm.Width; x += tmplBackground.Bitmap.Width) { for (int y = 0; y < bm.Height; y += tmplBackground.Bitmap.Height) g.DrawImage(tmplBackground.Bitmap, x, y); } } // Draw templates if ((lyrf & LayerFlags.Templates) != 0) { foreach (IMapItem mi in m_alsmi) { int x = (int)mi.tx * sizTile.Width; int y = (int)mi.ty * sizTile.Height; mi.Draw(g, x, y, sizTile, tmpd, LayerType.TileMap, alsmiSelected != null ? alsmiSelected.Contains(mi) : false); } } } }
public override bool OnMouseDown(System.Windows.Forms.MouseEventArgs e, Point ptMouse, Size sizTile, TemplateDoc tmpd) { int nHandle = HittestHandles(ptMouse, sizTile); if (nHandle != -1) { m_nHandleDragging = nHandle; Point ptCorner = GetCornerPoint(m_nHandleDragging, sizTile); m_xDeltaMouse = ptMouse.X - ptCorner.X; m_yDeltaMouse = ptMouse.Y - ptCorner.Y; return true; } return false; }
public override Rectangle GetBoundingRectAt(int x, int y, Size sizTile, TemplateDoc tmpd) { Size sizT = new Size(sizTile.Width * m_ctx, sizTile.Height * m_cty); return new Rectangle(x, y, sizT.Width, sizT.Height); }
public ArrayList HitTest(Rectangle rc, Size sizTile, TemplateDoc tmpd, LayerFlags lyrf) { ArrayList alsmi = new ArrayList(); foreach (IMapItem mi in m_alsmi) { Point ptCenter = mi.GetCenterPoint(sizTile); if (rc.Contains(ptCenter)) { if (mi is Area) { if ((lyrf & LayerFlags.Areas) != 0) alsmi.Add(mi); } else if (mi is Tile) { if ((lyrf & LayerFlags.Templates) != 0) alsmi.Add(mi); } else { if ((lyrf & LayerFlags.Gobs) != 0) alsmi.Add(mi); } } } return alsmi; }
public IMapItem HitTest(int x, int y, Size sizTile, TemplateDoc tmpd, LayerFlags lyrf) { // MapItems on top are first for (int i = m_alsmi.Count - 1; i >= 0; i--) { IMapItem mi = (IMapItem)m_alsmi[i]; if (mi.HitTest(x, y, sizTile, tmpd)) { if (mi is Area) { if ((lyrf & LayerFlags.Areas) != 0) return mi; } else if (mi is Tile) { if ((lyrf & LayerFlags.Templates) != 0) return mi; } else { if ((lyrf & LayerFlags.Gobs) != 0) return mi; } } } return null; }
public TerrainTypes[,] GetTerrainMap(Size sizTile, TemplateDoc tmpd, bool fStructures) { // Get raw terrain map TerrainTypes[,] aterMap = GetRawTerrainMap(sizTile, tmpd); // Flood fill to mark areas. The "biggest" area is accessible. // All the smaller areas are not; mark them as such. int[,] anFill = new int[aterMap.GetLength(0), aterMap.GetLength(1)]; // Mark all the areas in the fill map that are known to be not accessible. for (int ty = 0; ty < aterMap.GetLength(0); ty++) { for (int tx = 0; tx < aterMap.GetLength(1); tx++) { if (aterMap[ty, tx] == TerrainTypes.Blocked) { anFill[ty, tx] = -1; } } } // Mark structures if asked, before flood filling // This is used for terrain diffing to see if structures make terrain inaccessible if (fStructures) { foreach (IMapItem mi in m_alsmi) { if (mi is Structure) { for (int ty = (int)mi.ty; ty < mi.ty + mi.cty; ty++) { for (int tx = (int)mi.tx; tx < mi.tx + mi.ctx; tx++) { if (Bounds.Contains(tx, ty)) { int txT = tx - Bounds.Left; int tyT = ty - Bounds.Top; anFill[tyT, txT] = -1; } } } } } } // Start flood filling areas int nFillValue = 1; ArrayList alsFillCounts = new ArrayList(); alsFillCounts.Add(0); for (int ty = 0; ty < anFill.GetLength(0); ty++) { for (int tx = 0; tx < anFill.GetLength(1); tx++) { if (anFill[ty, tx] == 0) { int cFill = FloodFill(anFill, tx, ty, nFillValue); nFillValue++; alsFillCounts.Add(cFill); } } } // Find the largest count; that is the accessible area int nFillValueLargest = -1; int cLargest = 0; for (int n = 0; n < alsFillCounts.Count; n++) { if ((int)alsFillCounts[n] > cLargest) { cLargest = (int)alsFillCounts[n]; nFillValueLargest = n; } } // Now mark the areas that aren't this fill value as inaccessible for (int ty = 0; ty < anFill.GetLength(0); ty++) { for (int tx = 0; tx < anFill.GetLength(1); tx++) { if (anFill[ty, tx] != nFillValueLargest) { aterMap[ty, tx] = TerrainTypes.Blocked; } } } // Mark where areas are in the terrain foreach (IMapItem mi in m_alsmi) { if (mi is Area) { for (int ty = (int)mi.ty; ty < mi.ty + mi.cty; ty++) { for (int tx = (int)mi.tx; tx < mi.tx + mi.ctx; tx++) { if (Bounds.Contains(tx, ty)) { int txT = tx - Bounds.Left; int tyT = ty - Bounds.Top; if (aterMap[tyT, txT] == TerrainTypes.Open) aterMap[tyT, txT] = TerrainTypes.Area; } } } } } // Mark where walls are in the terrain foreach (IMapItem mi in m_alsmi) { if (mi is Wall) { int tx = (int)mi.tx; int ty = (int)mi.ty; if (Bounds.Contains(tx, ty)) { int txT = tx - Bounds.Left; int tyT = ty - Bounds.Top; aterMap[tyT, txT] = TerrainTypes.Wall; } } } // Done return aterMap; }
public TerrainColors[,] GetTerrainColorsMap(Size sizTile, TemplateDoc tmpd) { TerrainColors[,] atclrMap = new TerrainColors[Bounds.Height * 2, Bounds.Width * 2]; foreach (IMapItem mi in m_alsmi) { Tile tile = mi as Tile; if (tile == null) continue; int x = (int)mi.tx * sizTile.Width; int y = (int)mi.ty * sizTile.Height; Rectangle rc = tile.GetBoundingRectAt(x, y, sizTile, m_tmpd); rc.Width /= sizTile.Width; rc.Height /= sizTile.Height; rc.X /= sizTile.Width; rc.Y /= sizTile.Height; rc.Intersect(Bounds); for (int ty = rc.Y - (int)tile.ty; ty < rc.Bottom - (int)tile.ty; ty++) { for (int tx = rc.X - (int)tile.tx; tx < rc.Right - (int)tile.tx; tx++) { if (tile.Visibility == null || tile.Visibility[ty, tx]) { Template tmpl = tile.GetTemplate(m_tmpd); // Maybe this template doesn't exist in document's current tile collection if (tmpl == null) continue; // TerrainColors are a 2x2 subgrid inside each tile for (int tyT = 0; tyT < 2; tyT++) { for (int txT = 0; txT < 2; txT++) { TerrainColors tclr = TerrainColors.Grass; if (tmpl.TerrainColors != null) tclr = tmpl.TerrainColors[ty * 2 + tyT, tx * 2 + txT]; atclrMap[(ty + (int)tile.ty - Bounds.Y) * 2 + tyT, (tx + (int)tile.tx - Bounds.X) * 2 + txT] = tclr; } } } } } } return atclrMap; }
public Bitmap GetMapBitmap(Size sizTile, TemplateDoc tmpd, bool fTilesOnly) { Bitmap bm = new Bitmap(Width * sizTile.Width, Height * sizTile.Height, PixelFormat.Format24bppRgb); DrawTileMap(bm, null, sizTile, tmpd, LayerFlags.Default); if (!fTilesOnly) { using (Graphics g = Graphics.FromImage(bm)) { for (LayerType layer = LayerType.Galaxite; layer < LayerType.End; layer++) { foreach (IMapItem mi in m_alsmi) { int x = (int)(mi.tx * sizTile.Width); int y = (int)(mi.ty * sizTile.Height); mi.Draw(g, x, y, sizTile, tmpd, layer, false); } } } } Bitmap bmT = new Bitmap(Bounds.Width * sizTile.Width, Bounds.Height * sizTile.Height, PixelFormat.Format24bppRgb); using (Graphics g = Graphics.FromImage(bmT)) { Rectangle rcSrc = new Rectangle(Bounds.X * sizTile.Width, Bounds.Y * sizTile.Height, bmT.Width, bmT.Height); g.DrawImage(bm, 0, 0, rcSrc, GraphicsUnit.Pixel); } bm.Dispose(); return bmT; }
public override void Draw(Graphics g, int x, int y, Size sizTile, TemplateDoc tmpd, LayerType layer, bool fSelected) { if (layer == LayerType.Area) DrawArea(g, x, y, sizTile, fSelected); }
public override Bitmap GetBitmap(Size sizTile, TemplateDoc tmpd) { Bitmap bm = new Bitmap(sizTile.Width * m_ctx, sizTile.Height * m_cty); Graphics g = Graphics.FromImage(bm); DrawArea(g, 0, 0, sizTile, false); g.Dispose(); return bm; }
public override bool OnMouseUp(System.Windows.Forms.MouseEventArgs e, Point ptMouse, Size sizTile, TemplateDoc tmpd) { if (m_nHandleDragging != -1) { m_nHandleDragging = -1; return true; } return false; }
public override bool HitTest(int x, int y, Size sizTile, TemplateDoc tmpd) { int xT = x - (int)m_tx * sizTile.Width; int yT = y - (int)m_ty * sizTile.Height; Size sizT = new Size(sizTile.Width * m_ctx, sizTile.Height * m_cty); if (xT >= 0 && xT < sizT.Width && yT >= 0 && yT < sizT.Height) return true; return false; }
// IMapItem public override Bitmap GetBitmap(Size sizTile, TemplateDoc tmpd) { // Get the template. This'll invalidate m_bmCache if necessary Template tmpl = GetTemplate(tmpd); // If already cached, use it if (m_bmCache != null) return m_bmCache; // If we haven't mapped to a template, create a correctly sized bitmap as a placeholder bool fDispose = false; Bitmap bm; if (tmpl != null) { bm = tmpl.Bitmap; // Dont use the bitmap directly, it might have knobbies on that'll create // problems at compile time. #if false if (m_afVisible == null) return bm; #endif } else { fDispose = true; bm = new Bitmap(m_afOccupancy.GetLength(1) * sizTile.Width, m_afOccupancy.GetLength(0) * sizTile.Height); using (Graphics gT = Graphics.FromImage(bm)) gT.Clear(Color.Firebrick); } // Fill in the chunks that are visible int cxT = m_afOccupancy.GetLength(1) * sizTile.Width; int cyT = m_afOccupancy.GetLength(0) * sizTile.Height; m_bmCache = new Bitmap(cxT, cyT); using (Graphics g = Graphics.FromImage(m_bmCache)) { g.Clear(Color.FromArgb(255, 0, 255)); for (int ty = 0; ty < m_afOccupancy.GetLength(0); ty++) { for (int tx = 0; tx < m_afOccupancy.GetLength(1); tx++) { if (!m_afOccupancy[ty, tx]) continue; if (!IsVisible(tx, ty)) { continue; } Rectangle rcDst = new Rectangle(tx * sizTile.Width, ty * sizTile.Height, sizTile.Width, sizTile.Height); g.DrawImage(bm, rcDst, tx * sizTile.Width, ty * sizTile.Height, sizTile.Width, sizTile.Height, GraphicsUnit.Pixel); } } } if (fDispose) bm.Dispose(); // Hide the areas that are invisible TemplateTools.MakeTransparent(m_bmCache); return m_bmCache; }
public override bool OnMouseMove(System.Windows.Forms.MouseEventArgs e, Point ptMouse, Size sizTile, TemplateDoc tmpd) { if (m_nHandleDragging == -1) return false; Point ptCorner = GetCornerPoint(m_nHandleDragging, sizTile); int txOld = ptCorner.X / sizTile.Width; int tyOld = ptCorner.Y / sizTile.Height; int txNew = (ptMouse.X - m_xDeltaMouse) / sizTile.Width; int tyNew = (ptMouse.Y - m_yDeltaMouse) / sizTile.Height; if (txOld == txNew && tyOld == tyNew) return true; switch (m_nHandleDragging) { case 0: m_tx = txNew; m_ty = tyNew; m_ctx += txOld - txNew; m_cty += tyOld - tyNew; break; case 1: m_ty = tyNew; m_cty += tyOld - tyNew; m_ctx += txNew - txOld; break; case 2: m_ctx += txNew - txOld; m_cty += tyNew - tyOld; break; case 3: m_tx = txNew; m_ctx += txOld - txNew; m_cty += tyNew - tyOld; break; } m_ctx = Math.Max(1, m_ctx); m_cty = Math.Max(1, m_cty); OnPropertyChanged(this, "Bitmap"); return true; }
public void Draw(Bitmap bm, IMapItem miExclude, Size sizTile, TemplateDoc tmpd, LayerFlags lyrf) { ArrayList alsmiSelected = m_alsmiSelected; // Draw tile map DrawTileMap(bm, alsmiSelected, sizTile, tmpd, lyrf); // Draw other layers using (Graphics g = Graphics.FromImage(bm)) { for (LayerType layer = LayerType.Galaxite; layer < LayerType.End; layer++) { if (layer == LayerType.Area) { if ((lyrf & LayerFlags.Areas) == 0) continue; } else { if ((lyrf & LayerFlags.Gobs) == 0) continue; } foreach (IMapItem mi in m_alsmi) { if (mi != miExclude) { int x = (int)(mi.tx * sizTile.Width); int y = (int)(mi.ty * sizTile.Height); mi.Draw(g, x, y, sizTile, tmpd, layer, alsmiSelected != null ? alsmiSelected.Contains(mi) : false); } } } // Draw bounds Pen pen = new Pen(new SolidBrush(Color.FromArgb(0, 255, 0))); pen.Width = 2; g.DrawRectangle(pen, Bounds.X * sizTile.Width - pen.Width + 1, Bounds.Y * sizTile.Height - pen.Width + 1, Bounds.Width * sizTile.Width + pen.Width, Bounds.Height * sizTile.Height + pen.Width); } }
public static TemplateDoc CloneTemplateDoc(TemplateDoc tmpdSrc) { // This should probably be on ICloneable::Clone() on TemplateDoc TemplateDoc tmpdDst = (TemplateDoc)DocManager.NewDocument(typeof(TemplateDoc), new Object[] { tmpdSrc.TileSize }); DocManager.SetActiveDocument(typeof(TemplateDoc), tmpdSrc); Template[] atmplSrc = tmpdSrc.GetTemplates(); Template tmplSrcBackground = tmpdSrc.GetBackgroundTemplate(); Template tmplDstBackground = null; ArrayList alsTmplDst = new ArrayList(); foreach (Template tmplSrc in atmplSrc) { Template tmplDst = new Template(tmpdDst, tmplSrc.Name); tmplDst.OccupancyMap = tmplSrc.OccupancyMap; tmplDst.TerrainMap = tmplSrc.TerrainMap; tmplDst.Bitmap = (Bitmap)tmplSrc.Bitmap.Clone(); alsTmplDst.Add(tmplDst); if (tmplSrc == tmplSrcBackground) tmplDstBackground = tmplDst; } if (tmplDstBackground != null) tmpdDst.SetBackgroundTemplate(tmplDstBackground); tmpdDst.AddTemplates((Template[])alsTmplDst.ToArray(typeof(Template))); Palette palSrc = tmpdSrc.GetPalette(); if (palSrc != null) tmpdDst.SetPalette(palSrc, false); return tmpdDst; }
public static void QuantizeTemplates(TemplateDoc tmpd, Palette palFixed, int cPalEntries, int cPalEntriesFixed, int cPalEntriesBackground) { // Load the fixed palette. The result will be 24 bit templates normalized to a palette of 256 colors, // the "fixed" palette plus a quantized palette. if (palFixed == null) { palFixed = Palette.OpenDialog(null); if (palFixed == null) { MessageBox.Show(DocManager.GetFrameParent(), "Must have the fixed color palette to continue!"); return; } switch (palFixed.Length) { case 16: cPalEntries = 16; cPalEntriesFixed = 16; cPalEntriesBackground = 0; break; case 256: cPalEntries = 256; cPalEntriesFixed = 128; cPalEntriesBackground = 32; break; } } // Quantize loop. Designed to make optimal use of the lower 128 fixed colors // Quantize background separately from foreground Template tmplBackground = tmpd.GetBackgroundTemplate(); if (tmplBackground != null && cPalEntriesBackground != 0) { // Create a despeckled hue map of the background. We'll use this to // subtract background from foreground so we can quantize foreground separately Bitmap bmHueBackground = MakeHueMap(tmplBackground.Bitmap); DespeckleGrayscaleBitmap(bmHueBackground, 9, 50); // Calc mean and standard deviation for filtering purposes double nMean = CalcGrayscaleMean(bmHueBackground); double nStdDev = CalcGrayscaleStandardDeviation(bmHueBackground, nMean); // Add extract & quantize the background pixels ArrayList alsColorsBackground = new ArrayList(); AddTemplateColors(alsColorsBackground, tmplBackground.Bitmap); palFixed = QuantizeColors(alsColorsBackground, palFixed, cPalEntriesFixed + cPalEntriesBackground, cPalEntriesFixed); cPalEntriesFixed += cPalEntriesBackground; // Now extract foreground pixels by first subtracting background pixels ArrayList alsColorsForeground = new ArrayList(); Template[] atmpl = tmpd.GetTemplates(); foreach (Template tmpl in atmpl) { if (tmpl == tmplBackground) continue; Bitmap bmT = MakeHueMap(tmpl.Bitmap); DespeckleGrayscaleBitmap(bmT, 9, 50); SubtractGrayscaleDistribution(bmT, nMean, nStdDev); for (int y = 0; y < bmT.Height; y++) { for (int x = 0; x < bmT.Width; x++) { Color clr = bmT.GetPixel(x, y); if (clr != Color.FromArgb(255, 0, 255)) bmT.SetPixel(x, y, tmpl.Bitmap.GetPixel(x, y)); } } AddTemplateColors(alsColorsForeground, bmT); } // Now quantize foreground pixels // Set the palette and color match Palette palNew = QuantizeColors(alsColorsForeground, palFixed, cPalEntries, cPalEntriesFixed); tmpd.SetPalette(palNew, true); } else { // No background template; just quantize everything together Template[] atmpl = tmpd.GetTemplates(); ArrayList alsColors = new ArrayList(); foreach (Template tmpl in atmpl) AddTemplateColors(alsColors, tmpl.Bitmap); // Now quantize foreground pixels // Set the palette and color match Palette palNew = QuantizeColors(alsColors, palFixed, cPalEntries, cPalEntriesFixed); tmpd.SetPalette(palNew, true); } }
public override Rectangle GetBoundingRectAt(int x, int y, Size sizTile, TemplateDoc tmpd) { Bitmap bm = GetBitmap(sizTile, tmpd); return new Rectangle(x, y, bm.Width, bm.Height); }
public Template GetTemplate(TemplateDoc tmpd) { if (tmpd == m_tmpdCache) return m_tmplCache; m_tmpdCache = null; m_tmplCache = null; m_bmCache = null; if (tmpd == null) return null; Template tmpl = tmpd.FindTemplate(m_strName); if (tmpl != null) { m_tmpdCache = tmpd; m_tmplCache = tmpl; m_afOccupancy = tmpl.OccupancyMap; return tmpl; } return null; }
public override bool HitTest(int x, int y, Size sizTile, TemplateDoc tmpd) { int xOffset = x - (int)m_tx * sizTile.Width; int yOffset = y - (int)m_ty * sizTile.Height; Rectangle rc = new Rectangle(new Point(0, 0), GetBitmap(sizTile, tmpd).Size); if (!rc.Contains(xOffset, yOffset)) return false; int tx = xOffset / sizTile.Width; int ty = yOffset / sizTile.Height; try { if (m_afVisible != null) return IsVisible(tx, ty); return m_afOccupancy[ty, tx]; } catch { return false; } }
private void TemplateDocTemplate_TemplatesRemovedHandler(TemplateDoc tmpd, string[] astrNames) { TemplatesAddedRemoved(astrNames); }
void TemplateDocTemplate_TemplateChanged(TemplateDoc tmpd, string strProperty, string strName, string strParam) { if (m_strName != strName) return; // Flush cached items GetTemplate(null); // Handle changes switch (strProperty) { case "Name": m_strName = strParam; OnPropertyChanged(this, "Name"); break; case "Bitmap": OnPropertyChanged(this, "Bitmap"); break; } }
void TemplateDoc_BackgroundChangedHandler(TemplateDoc tmpd) { m_fUpdateDirty = true; }