public TextureRegion(TextureRegion src) { group_name = src.group_name; name = src.name; visible = true; tag = null; rect = src.rect; }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); bool need_to_redraw = selected_regions.Count > 0; int mouse_x = e.X; int mouse_y = e.Y; float x = (float)m_visible_rect.X; float y = (float)m_visible_rect.Y; if (e.Button == MouseButtons.Right) { Cursor = Cursors.Hand; old_x = e.X; old_y = e.Y; } else if (e.Button == MouseButtons.Left) { if (shift_key) { foreach (UI.TextureRegion r in regions) { if (r.GetRect(x, y, m_scale).Contains(new Point(mouse_x, mouse_y))) { UI.TextureRegion r1 = new UI.TextureRegion(r); r1.Name += "Copy"; AddTextureRegion(r1, true); m_state.action = AppState.Action.Moving; m_state.rect_part = RectParts.None; return; } } } if (control_key) { UI.TextureRegion r1 = new UI.TextureRegion(); r1.Rectangle = new Rectangle(mouse_x, mouse_y, 4, 4); r1.Name = "New Region"; AddTextureRegion(r1, true); m_state.action = AppState.Action.Resizing; m_state.rect_part = RectParts.RightDownSizer; return; } foreach (UI.TextureRegion r in selected_regions) { need_to_redraw = true; RectParts p = TestMouseHover(r, e.X, e.Y); m_state.rect_part = p; switch (p) { case RectParts.Body: m_state.action = AppState.Action.Moving; return; case RectParts.LeftDownSizer: case RectParts.LeftTopSizer: case RectParts.RightDownSizer: case RectParts.RightTopSizer: m_state.action = AppState.Action.Resizing; return; } } selected_regions.Clear(); foreach (UI.TextureRegion r in hovered_regions) { AddToSelection(r); need_to_redraw = true; RectParts p = TestMouseHover(r, e.X, e.Y); m_state.rect_part = p; switch (p) { case RectParts.Body: m_state.action = AppState.Action.Moving; return; case RectParts.LeftDownSizer: case RectParts.LeftTopSizer: case RectParts.RightDownSizer: case RectParts.RightTopSizer: m_state.action = AppState.Action.Resizing; return; } } } if (need_to_redraw) Invalidate(); }
private void openToolStripButton_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Imageset Files|*.imageset"; if (DialogResult.OK == ofd.ShowDialog(this)) { layout_editor.ClearUndoRedo(); layout_editor.Clear(); treeView1.Nodes.Clear(); imageset_filename = ofd.FileName; this.Text = ofd.FileName; using(FileStream fs = new FileStream(ofd.FileName, FileMode.Open)) { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(fs); XmlNode imageset_node = doc["Imageset"]; //<Imageset Name="Abilities" Imagefile="Abilities.tga" imageset_name = imageset_node.Attributes["Name"].Value; imagefile = imageset_node.Attributes["Imagefile"].Value; imagefile = System.IO.Path.GetDirectoryName(ofd.FileName) + "\\" + imagefile; imagefile = imagefile.ToLower(); layout_editor.Image = DevIL.DevIL.LoadBitmap(imagefile); if (null == layout_editor.Image && imagefile.Contains(".tga")) { string imagefile_copy = imagefile.Replace(".tga", ".dds"); Image image = DevIL.DevIL.LoadBitmap(imagefile); if (null != image) { imagefile = imagefile_copy; layout_editor.Image = image; } } if (null != layout_editor.Image) { NativeHorzRes = layout_editor.Image.Width; NativeVertRes = layout_editor.Image.Height; } //NativeHorzRes="1024" NativeVertRes="1024" if (null != imageset_node.Attributes["NativeHorzRes"]) NativeHorzRes = System.Convert.ToInt32(imageset_node.Attributes["NativeHorzRes"].Value); if (null != imageset_node.Attributes["NativeHorzRes"]) NativeVertRes = System.Convert.ToInt32(imageset_node.Attributes["NativeVertRes"].Value); // AutoScaled="true"> AutoScaled = true; if (null != imageset_node.Attributes["AutoScaled"]) AutoScaled = System.Convert.ToBoolean(imageset_node.Attributes["AutoScaled"].Value); foreach (XmlNode node in imageset_node.ChildNodes) { //XmlElement XmlElement el = node as XmlElement; if (null == el) continue; TextureRegion t = new TextureRegion(); //<Image Name="TestAbility_2" YPos="0" XPos="40" Width="40" Height="40" /> t.Name = node.Attributes["Name"].Value; int x = System.Convert.ToInt32(node.Attributes["XPos"].Value); int y = System.Convert.ToInt32(node.Attributes["YPos"].Value); int w = System.Convert.ToInt32(node.Attributes["Width"].Value); int h = System.Convert.ToInt32(node.Attributes["Height"].Value); Rectangle r = new Rectangle(x, y, w, h); t.Rectangle = r; layout_editor.AddTextureRegion(t, false); } layout_editor.Invalidate(); } } }
void layout_editor_OnSelectRegion(TextureRegion reg) { treeView1.SelectedNode = reg.Tag as TreeNode; propertyGrid.SelectedObject = reg; }
void layout_editor_OnDeleteRegion(TextureRegion reg) { if (reg.Tag != null) { TreeNode node = reg.Tag as TreeNode; node.Remove(); } }
void layout_editor_OnAddRegion(TextureRegion reg) { CreateTreeNode(reg.Name, reg); }
TreeNode CreateTreeNode(string name, TextureRegion reg) { TreeNode node = new TreeNode(name); node.Tag = reg; reg.Tag = node; node.ImageIndex = 2; node.SelectedImageIndex = 2; node.Checked = true; if (treeView1.SelectedNode != null) { if (treeView1.SelectedNode.Tag == null) { treeView1.SelectedNode.Nodes.Add(node); } else if (treeView1.SelectedNode.Parent != null) { treeView1.SelectedNode.Parent.Nodes.Add(node); } else treeView1.Nodes.Add(node); } else { treeView1.Nodes.Add(node); } return node; }