private void Screen_MouseMove(object sender, MouseEventArgs e) { if (Scene == null) { return; } var eX = e.X / Scene.Zoom; var eY = e.Y / Scene.Zoom; var realLocation = new Point(eX, eY); if (gridToolStripButton.Checked) { eX = (eX / 8) * 8; eY = (eY / 8) * 8; } var eLocation = new Point(eX, eY); if (held != null) { held.Position = new Point(eX - heldOffset.X, eY - heldOffset.Y); if (held.Position.X < 0) { held.Position = new Point(0, held.Position.Y); } if (held.Position.Y < 0) { held.Position = new Point(held.Position.X, 0); } if (held.Position.X + held.Bounds.Width > Scene.Bitmap.Width) { held.Position = new Point(Scene.Bitmap.Width - held.Bounds.Width, held.Position.Y); } if (held.Position.Y + held.Bounds.Height > Scene.Bitmap.Height) { held.Position = new Point(held.Position.X, Scene.Bitmap.Height - held.Bounds.Height); } if (held.Fix > 0) { if (Tools.Distance(fix, held.Position) > FixSnap) { held.Fix--; if (held.Fix == 0) { if (!Scene.RunEvent(string.Format("unfix|{0}", HilightedCel))) { Scene.RunEvent(string.Format("unfix|{0}", held)); } } held.Position = new Point(fix.X, fix.Y); held = null; } } DrawScene(); return; } var cel = default(Cel); var part = Scene.GetPartFromPoint(realLocation, out cel); var statusPart = part; if (statusPart == null && HilightedCel != null) { statusPart = HilightedCel.Part; } if (statusPart != null && cel != null) { mainStatusStrip.Items[0].Text = string.Format("{0} » {1}", statusPart.ID, cel.ID); mainStatusStrip.Items[1].Text = string.Format("{0} by {1}", statusPart.Position.X, statusPart.Position.Y); mainStatusStrip.Items[2].Image = (statusPart.Locked || statusPart.Fix > 0) ? refixToolStripMenuItem.Image : unfixToolStripMenuItem.Image; mainStatusStrip.Items[3].Text = statusPart.Fix.ToString(); } else { mainStatusStrip.Items[0].Text = mainStatusStrip.Items[1].Text = mainStatusStrip.Items[3].Text = string.Empty; mainStatusStrip.Items[2].Image = null; } if (lastCelPointed != cel) { if (lastCelPointed != null) { if (Scene.RunEvent("mouseout|{0}", lastCelPointed.ID)) { DrawScene(); } else { if (Scene.RunEvent("mouseout|{0}", lastCelPointed.Part.ID)) { DrawScene(); } } } if (cel != null) { if (Scene.RunEvent("mousein|{0}", cel.ID)) { DrawScene(); } else { if (Scene.RunEvent("mousein|{0}", part.ID)) { DrawScene(); } } } lastCelPointed = cel; } if (cel != null && cel is ButtonCel) { if (lastButton != null && lastButton != cel) { lastButton.State = 0; } if (lastButton != cel) { lastButton = (ButtonCel)cel; if (lastButton.State == 0) { lastButton.State = 2; DrawScene(); } } } else if (lastButton != null) { lastButton.State = 0; lastButton = null; DrawScene(); } if (part == null) { if (dragStart == null) { activeScreen.Cursor = Cursors.Default; } else { activeScreen.Cursor = Cursors.SizeAll; var dragPoint = screenContainerPanel.PointToClient(screenPictureBox.PointToScreen(realLocation)); if (screenContainerPanel.HorizontalScroll.Visible) { var x = -startScroll.X + (dragStart.Value.X - dragPoint.X); var y = -startScroll.Y + (dragStart.Value.Y - dragPoint.Y); screenContainerPanel.AutoScrollPosition = new Point(x, y); } } } else if (part.Locked) { activeScreen.Cursor = Cursors.Default; } else { activeScreen.Cursor = Cursors.Hand; } }
public Cel ParseCelForm(List <object> celItem) { Bitmap image = null; var file = ""; var id = ""; var partof = ""; var alpha = 255; var positions = new List <object>() { 0, 0 }; var offset = new List <object>() { 0, 0 }; var on = defaultOn; //"0123456789"; var fix = 0; var newPos = false; var newFix = false; var mapped = true; var ghosted = false; var labelText = ""; var labelWidth = 0; var labelFont = new Font("Tahoma", 8); var labelColor = Color.Black; var labelCenter = false; var celType = ""; for (var i = 0; i < celItem.Count; i++) { var form = celItem[i] as Symbol; switch (form) { case null: break; case "file": { i++; file = celItem[i] as string; if (id == "") { id = file; } if (partof == "") { partof = id; } celType = "pic"; } break; case "label": { celType = "label"; } break; case "button": { i++; file = celItem[i] as string; celType = "button"; } break; case "id": { i++; if (partof == id) { partof = ""; } id = celItem[i] as string; if (partof == "") { partof = id; } } break; case "partof": { i++; partof = celItem[i] as string; } break; case "alpha": { i++; alpha = (int)celItem[i]; } break; case "pos": { i++; positions = celItem[i] as List <object>; newPos = true; } break; case "offset": { i++; offset = celItem[i] as List <object>; } break; case "fix": { i++; fix = (int)celItem[i]; newFix = true; } break; case "locked": { fix = MaxFix; newFix = true; } break; case "on": { i++; on = celItem[i] as string; } break; case "unmapped": { mapped = false; } break; case "ghost": { ghosted = true; } break; case "group": break; case "text": { i++; labelText = celItem[i] as string; } break; case "width": { i++; labelWidth = (int)celItem[i]; } break; case "color": { i++; var bgi = celItem[i] as List <object>; if (bgi.Count == 3 && bgi[0] is int && bgi[1] is int && bgi[2] is int) { labelColor = Color.FromArgb((int)bgi[0], (int)bgi[1], (int)bgi[2]); } } break; case "font": { i++; var f = labelFont.Name; var p = labelFont.Size; var s = FontStyle.Regular; if (celItem[i] is string) { f = celItem[i] as string; } else if (celItem[i] is List <object> ) { var bgi = celItem[i] as List <object>; f = bgi[0] as string; if (bgi.Count > 1) { p = (int)bgi[1]; } if (bgi.Count > 2) { for (var j = 2; j < bgi.Count; j++) { if (bgi[j] is Symbol && (Symbol)bgi[j] == "bold") { s |= FontStyle.Bold; } if (bgi[j] is Symbol && (Symbol)bgi[j] == "italic") { s |= FontStyle.Italic; } if (bgi[j] is Symbol && (Symbol)bgi[j] == "center") { labelCenter = true; } } } } labelFont = new Font(f, p, s); } break; } } //try to preload the image if (celType == "pic" || celType == "button") { try { image = Tools.GrabClonedBitmap(file + ".png", Mix); } catch (System.IO.FileNotFoundException ex) { DarkUI.Forms.DarkMessageBox.ShowWarning(ex.Message, Application.ProductName); return(null); } } //find the partof object var part = Parts.FirstOrDefault(o => o.ID == partof); if (part == null) { part = new Part(this) { ID = partof, Cels = new List <Cel>(), }; Parts.Add(part); } if (newPos) { if (positions[0] is int) { //pos (12 34) --> pos ((12 34)) positions = new List <object>() { positions }; } while (positions.Count < 10) { positions.Add(positions[0]); } for (var i = 0; i < 10; i++) { if (positions[i] is Symbol && positions[i].ToString() == "*") { if (i == 0) { positions[i] = new List <object>() { 0, 0 } } ; else { positions[i] = positions[0]; } } var pos = positions[i] as List <object>; part.Positions[i] = new Point((int)pos[0], (int)pos[1]); if (pos.Count > 2 && pos[2].ToString() == ">") { pos.RemoveAt(2); for (var j = i + 1; j < 10; j++) { positions[j] = positions[i]; } } } for (var i = 0; i < 10; i++) { part.InitialPositions[i] = part.Positions[i]; } } if (newFix) { part.Fix = part.InitialFix = fix; } var c = new Cel(this) { Image = image, ImageFilename = file + ".png", Visible = mapped, ID = id, Opacity = alpha, Ghost = ghosted, }; if (celType == "label") { c = new TextCel(this) { Width = labelWidth, Color = labelColor, Font = labelFont, Centered = labelCenter, Visible = mapped, ID = id, Opacity = alpha, Ghost = ghosted, }; ((TextCel)c).Text = labelText; ((TextCel)c).Draw(); } if (celType == "button") { c = new ButtonCel(this, c) { Visible = mapped, ID = id, Opacity = alpha, Ghost = ghosted, }; ((ButtonCel)c).Draw(); } foreach (var s in on) { if (!char.IsDigit(s)) { continue; } var i = (int)(s - '0'); c.OnSets[i] = true; } c.Offset = new Point((int)offset[0], (int)offset[1]); c.Part = part; part.Cels.Add(c); part.UpdateBounds(); Cels.Add(c); return(c); }