public void InitForFrame(_frameItem fi) { DisableAll(); cmbAlias.Items.Clear(); if (fi.names.Count > 0) { rbAlias.Enabled = true; } string grid = ""; foreach (_frameName fn in fi.names) { if (fn.source == FrameSource.Grid) { grid = fn.name; } else if (fn.source == FrameSource.Name) { grid = ""; } cmbAlias.Items.Add(fn.name); } if (grid != "") { InitGridName(grid); } InitListFrame(fi.x, fi.y, fi.width, fi.height); }
public void RemoveFrame(_frameName fn) { bool bRemove = false; if ((fn.source == FrameSource.List) && (frameList != null)) { frameList.Remove(fn.name); if (frameList.Count == 0) { frameList = null; } bRemove = true; } else if ((fn.source == FrameSource.Name) && (frameGrid != null) && (frameGrid.names != null)) { for (int i = 0; i < frameGrid.names.Count; i++) { for (int j = 0; j < frameGrid.names[i].Count; j++) { if (frameGrid.names[i][j] == fn.name) { frameGrid.names[i][j] = null; bRemove = true; break; } } if (bRemove) { break; } } } else if ((fn.source == FrameSource.Alias) && (aliases != null)) { aliases.Remove(fn.name); if (aliases.Count == 0) { aliases = null; } bRemove = true; } if (bRemove) { _frameItem fi = GetFrameItemOf(fn); if (fi != null) { fi.RemoveName(fn.name); if (fi.names.Count == 0) { ListFrameItems.Remove(fi); } LookupFrameItems.Remove(fn.name); } } }
public void SetFrameToList(_frameItem fi, _frameName fn) { fn.source = FrameSource.List; if (frameList == null) { frameList = new Dictionary <string, int[]>(); } frameList.Add(fn.name, new int[] { fi.x, fi.y, fi.x + fi.width - 1, fi.y + fi.height - 1 }); }
public void SetFrameToList(_frameItem fi, string n) { for (int i = 0; i < fi.names.Count; i++) { if (fi.names[i].name == n) { SetFrameToList(fi, fi.names[i]); return; } } }
public void AddAlias(string a, string ao) { _frameItem fi = GetFrameItemOf(ao); if (fi != null) { fi.AddName(a, FrameSource.Alias, ao); LookupFrameItems.Add(a, fi); if (aliases == null) { aliases = new Dictionary <string, string>(); } aliases.Add(a, ao); } }
void CleanupAliasesAt(_frameItem fi) { for (int i = 0; i < fi.names.Count; i++) { if (fi.names[i].source == FrameSource.Alias) { _frameName fn = fi.names.Find(tfn => tfn.name == fi.names[i].aliasof); if (fn == null) { LookupFrameItems.Remove(fi.names[i].name); aliases.Remove(fi.names[i].name); fi.names.RemoveAt(i--); } } } }
public void AddFrameListItem(string n, int x, int y, int w, int h) { _frameItem item = GetFrameItemOfSize(x, y, w, h); if (item == null) { item = new _frameItem(x, y, w, h); ListFrameItems.Add(item); } LookupFrameItems.Add(n, item); item.AddName(n, FrameSource.List); if (frameList == null) { frameList = new Dictionary <string, int[]>(); } frameList.Add(n, new int[] { x, y, x + w - 1, y + h - 1 }); }
public void UpdateFrameListItem(_frameItem fi) { if (frameList == null) { return; } foreach (_frameName fn in fi.names) { if (fn.source == FrameSource.List) { int[] v = frameList[fn.name]; v[0] = fi.x; v[1] = fi.y; v[2] = fi.width; v[3] = fi.height; frameList[fn.name] = v; break; } } }
public void SetFrameGridName(string d, string n) { if (frameGrid == null) { return; } string on = frameGrid.SetNameFor(d, n); if (on == null) { return; } else { _frameItem fi = GetFrameItemOf(d); if (on == "") { fi.AddName(n, FrameSource.Name); } else { foreach (_frameName fn in fi.names) { if (fn.name == on) { fn.name = n; break; } } LookupFrameItems.Remove(on); } LookupFrameItems.Add(n, fi); } }
protected override void OnMouseMove(MouseEventArgs e) { if (e.Button == MouseButtons.None) { /*if (Control.ModifierKeys == Keys.Shift) * { * Cursor = Cursors.NoMove2D; * } * else*/ if (WorkingFrameItem != null) { Matrix IT = LastTransform.Clone(); IT.Invert(); Point[] p = new Point[] { new Point(e.X, e.Y) }; IT.TransformPoints(p); if (Globals.WorkingFrames.Img != null) { p[0].X -= LastImageOffset.X; p[0].Y -= LastImageOffset.Y; } _frameItem FI = Globals.WorkingFrames.GetItemUnder(p[0].X, p[0].Y, ValidFramesFlag); if (WorkingFrameItem == null) { cbFrameNames.Items.Clear(); } if (FI != null) { bool fromList = false; string name; foreach (_frameName fn in FI.names) { if ((fn.source & ValidFramesFlag) == 0) { continue; } name = fn.name; if (fn.source == FrameSource.Grid) { name += " (default)"; } else if (fn.source == FrameSource.List) { name += " (list)"; fromList = true; } else if (fn.source == FrameSource.Name) { name += " (name)"; } else if (fn.source == FrameSource.Alias) { name += " (alias)"; } if (WorkingFrameItem == null) { cbFrameNames.Items.Add(name); } } if (WorkingFrameItem == null) { cbFrameNames.SelectedIndex = 0; } if (fromList) { EEdgeCorner ec = FI.GetEdgeOrCorner(p[0].X, p[0].Y, 5); Cursor = cursors[(int)ec]; } } else { if (WorkingFrameItem == null) { cbFrameNames.Text = ""; } Cursor = cursors[0]; } } return; } if (EditMode == EEditMode.EM_Translate) { Translation[0] += e.X - LastMovePos[0]; Translation[1] += e.Y - LastMovePos[1]; LastMovePos[0] = e.X; LastMovePos[1] = e.Y; Invalidate(); } else if (EditMode == EEditMode.EM_Resize) { ResizeMovement[0] += (e.X - LastMovePos[0]) / (float)ZoomLevels[ZoomIndex]; ResizeMovement[1] += (e.Y - LastMovePos[1]) / (float)ZoomLevels[ZoomIndex]; LastMovePos[0] = e.X; LastMovePos[1] = e.Y; int rx = (int)ResizeMovement[0]; ResizeMovement[0] -= rx; int ry = (int)ResizeMovement[1]; ResizeMovement[1] -= ry; if (ResizeDir == EEdgeCorner.TopLeft) { if ((WorkingFrameItem.x + rx >= 0) && (WorkingFrameItem.width - rx > 1)) { WorkingFrameItem.x += rx; WorkingFrameItem.width -= rx; } if ((WorkingFrameItem.y + ry >= 0) && (WorkingFrameItem.height - ry > 1)) { WorkingFrameItem.y += ry; WorkingFrameItem.height -= ry; } } else if (ResizeDir == EEdgeCorner.Top) { if ((WorkingFrameItem.y + ry >= 0) && (WorkingFrameItem.height - ry > 1)) { WorkingFrameItem.y += ry; WorkingFrameItem.height -= ry; } } else if (ResizeDir == EEdgeCorner.TopRight) { if (WorkingFrameItem.width + rx > 1) { WorkingFrameItem.width += rx; } if ((WorkingFrameItem.y + ry >= 0) && (WorkingFrameItem.height - ry > 1)) { WorkingFrameItem.y += ry; WorkingFrameItem.height -= ry; } } else if (ResizeDir == EEdgeCorner.Left) { if ((WorkingFrameItem.x + rx >= 0) && (WorkingFrameItem.width - rx > 1)) { WorkingFrameItem.x += rx; WorkingFrameItem.width -= rx; } } else if (ResizeDir == EEdgeCorner.Right) { if (WorkingFrameItem.width + rx > 1) { WorkingFrameItem.width += rx; } } else if (ResizeDir == EEdgeCorner.BottomLeft) { if ((WorkingFrameItem.x + rx >= 0) && (WorkingFrameItem.width - rx > 1)) { WorkingFrameItem.x += rx; WorkingFrameItem.width -= rx; } if (WorkingFrameItem.height + ry > 1) { WorkingFrameItem.height += ry; } } else if (ResizeDir == EEdgeCorner.Bottom) { if (WorkingFrameItem.height + ry > 1) { WorkingFrameItem.height += ry; } } else if (ResizeDir == EEdgeCorner.BottomRight) { if (WorkingFrameItem.width + rx > 1) { WorkingFrameItem.width += rx; } if (WorkingFrameItem.height + ry > 1) { WorkingFrameItem.height += ry; } } if ((rx != 0) || (ry != 0)) { Globals.WorkingFrames.UpdateFrameListItem(WorkingFrameItem); Invalidate(); } } }
protected override void OnMouseClick(MouseEventArgs e) { if (EditMode != EEditMode.EM_None) { return; } if (Globals.WorkingFrames != null) { Matrix IT = LastTransform.Clone(); IT.Invert(); Point[] p = new Point[] { new Point(e.X, e.Y) }; IT.TransformPoints(p); if (Globals.WorkingFrames.Img != null) { p[0].X -= LastImageOffset.X; p[0].Y -= LastImageOffset.Y; } WorkingFrameItem = Globals.WorkingFrames.GetItemUnder(p[0].X, p[0].Y, ValidFramesFlag); cbFrameNames.Items.Clear(); if (WorkingFrameItem != null) { string name; foreach (_frameName fn in WorkingFrameItem.names) { if ((fn.source & ValidFramesFlag) == 0) { continue; } name = fn.name; if (fn.source == FrameSource.Grid) { name += " (default)"; } else if (fn.source == FrameSource.List) { name += " (list)"; } else if (fn.source == FrameSource.Name) { name += " (name)"; } else if (fn.source == FrameSource.Alias) { name += " (alias)"; } cbFrameNames.Items.Add(name); } cbFrameNames.SelectedIndex = 0; btnRemoveFrame.Enabled = true; } else { cbFrameNames.Text = ""; btnRemoveFrame.Enabled = false; } if (e.Button == MouseButtons.Right) { if (WorkingFrameItem != null) { } } Invalidate(); } }
void btnRemoveFrame_Clicked(object sender, EventArgs e) { if (WorkingFrameItem == null) { btnRemoveFrame.Enabled = false; return; } List <_frameName> fns; DialogResult dr; _frameName curFrame = WorkingFrameItem.names[cbFrameNames.SelectedIndex]; if (curFrame.source == FrameSource.Grid) { // not normally able to delete default frames. only solution is to copy all default frames to the frameList set and then remove the frameGrid } else { fns = Globals.WorkingFrames.GetAliasesFor(curFrame.name); bool bDelete = false; if (fns.Count > 0) { dr = MessageBox.Show("Deleting the frame '" + curFrame.name + "' will delete " + fns.Count + " aliases. Do you want to move them to a different frame instead?", "Dependancy Check", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { // build exclude list List <string> excludes = new List <string>(); excludes.Add(curFrame.name); foreach (_frameName fn in fns) { excludes.Add(fn.name); } FrameSelectForm fsf = new FrameSelectForm(); fsf.InitFor(Globals.WorkingFrames, excludes); dr = fsf.ShowDialog(); if (dr == DialogResult.OK) { string nn = fsf.Value; if (nn != null) { foreach (_frameName fn in fns) { fn.aliasof = nn; WorkingFrameItem.RemoveName(fn.name); _frameItem fi = Globals.WorkingFrames.ListFrameItems.Find(f => f.names.Exists(n => n.name == nn)); if (fi != null) { fi.names.Add(fn); } Globals.WorkingFrames.aliases[fn.name] = nn; } bDelete = true; } } } else if (dr == DialogResult.No) { foreach (_frameName fn in fns) { RemoveFrame(fn); } bDelete = true; } } else { dr = MessageBox.Show("Are you sure you want to delete the frame '" + curFrame.name + "'?", "Deletion Check", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { bDelete = true; } } if (bDelete) { RemoveFrame(curFrame); WorkingFrameItem = null; cbFrameNames.Items.Clear(); if (Globals.WorkingFrames.aliases == null) { cbShowAliases.Checked = false; cbShowAliases.Enabled = false; } if (Globals.WorkingFrames.frameList == null) { cbShowList.Checked = false; cbShowList.Enabled = false; } Invalidate(); } } }
public void RecalcFrameItems() { LookupFrameItems.Clear(); ListFrameItems.Clear(); _frameItem item = null; if (frameGrid != null) { string name; for (int j = 0; j < frameGrid.dimensions[1]; j++) { for (int i = 0; i < frameGrid.dimensions[0]; i++) { name = (i + j * frameGrid.dimensions[0]).ToString(); item = new _frameItem(i * frameGrid.size[0], j * frameGrid.size[1], frameGrid.size[0], frameGrid.size[1]); item.AddName(name, FrameSource.Grid); LookupFrameItems.Add(name, item); ListFrameItems.Add(item); } } if (frameGrid.names != null) { for (int j = 0; j < frameGrid.names.Count; j++) { for (int i = 0; i < frameGrid.names[j].Count; i++) { if (string.IsNullOrEmpty(frameGrid.names[j][i])) { continue; } if (LookupFrameItems.ContainsKey(frameGrid.names[j][i])) { continue; } name = frameGrid.names[j][i]; if ((i < frameGrid.dimensions[0]) && (j < frameGrid.dimensions[1])) { item = LookupFrameItems[(i + j * frameGrid.dimensions[0]).ToString()]; } else { item = new _frameItem(i * frameGrid.size[0], j * frameGrid.size[1], frameGrid.size[0], frameGrid.size[1]); ListFrameItems.Add(item); } LookupFrameItems.Add(name, item); item.AddName(name, FrameSource.Name); } } } } if (frameList != null) { foreach (KeyValuePair <string, int[]> entry in frameList) { item = GetFrameItemOfSize(entry.Value[0], entry.Value[1], entry.Value[2] - entry.Value[0] + 1, entry.Value[3] - entry.Value[1] + 1); if (item == null) { item = new _frameItem(entry.Value[0], entry.Value[1], entry.Value[2] - entry.Value[0] + 1, entry.Value[3] - entry.Value[1] + 1); ListFrameItems.Add(item); } LookupFrameItems.Add(entry.Key, item); item.AddName(entry.Key, FrameSource.List); } } if (aliases != null) { foreach (KeyValuePair <string, string> entry in aliases) { if (LookupFrameItems.ContainsKey(entry.Key)) { continue; } if (!LookupFrameItems.ContainsKey(entry.Value)) { continue; } item = LookupFrameItems[entry.Value]; item.AddName(entry.Key, FrameSource.Alias, entry.Value); LookupFrameItems.Add(entry.Key, item); } } }