private void LbOids_SelectedIndexChanged(object sender, EventArgs e) { if (lbOids.SelectedItem != null && selectedScene != null) { selectedSceneOid = selectedScene.SceneOids.Where(x => x.SetupName == lbOids.SelectedItem.ToString()).FirstOrDefault(); if (selectedSceneOid == null) { var nso = new SceneOid(lbOids.SelectedItem.ToString()); selectedScene.SceneOids.Add(nso); selectedSceneOid = nso; } if (selectedSceneOid.Polygons == null) { selectedSceneOid.Polygons = new List <Polygon>(); } selectedpolygon = selectedSceneOid.Polygons.FirstOrDefault(); if (selectedpolygon == null) { var p = new Polygon(); selectedSceneOid.Polygons.Add(p); selectedpolygon = p; } tsPolygons.Items.Clear(); tsPolygons.Items.AddRange(selectedSceneOid.Polygons.ToArray()); if (tsPolygons.Items.Count > 0) { tsPolygons.SelectedIndex = 0; } } }
private static void DrawPolygons(Bitmap maskPicture, Graphics graphic, SceneOid sc, Image MaskImage, bool highquality) { foreach (Polygon pl in sc.Polygons) { var r = pl.GetBound(); float Xs = r.Left; float Xe = r.Right; float Ys = r.Top; float Ye = r.Bottom; var width = MaskImage.Width; var height = MaskImage.Height; for (float x = Xs; x < Xe; x += width) { for (float y = Ys; y < Ye; y += height) { int ci = CountEdges(pl, x, y, width, height); if (ci == 4) { if (highquality) { DrawFull(pl, (Bitmap)MaskImage, maskPicture, (int)x, (int)y); } else { graphic.DrawImage(MaskImage, (int)x, (int)y, width, height); } } else if (ci > 0) { DrawEdge(pl, (Bitmap)MaskImage, maskPicture, (int)x, (int)y); } } } } }
public FrmGraphicsEditor() { InitializeComponent(); PolyEditMode = EnumPolyEditMode.MoveImage; Overlay = new GraphicalOverlay() { Owner = pbDrawSpace }; Overlay.Paint += Overlay_Paint; InitTSEvents(); InitPbDrawSpace(); btnNewTTImage.Click += BtnTTImageNew_Click; btnDelTTImage.Click += (_, __) => { if (lbTTImages.SelectedItem != null) { selectedScene.TTImages.RemoveAt(lbTTImages.SelectedIndex); RefreshTTImages(); Overlay.Refresh(); } }; btnMoveUpTTImage.Click += (_, __) => { if (lbTTImages.SelectedIndex > 0) { SwapImages(lbTTImages.SelectedIndex, lbTTImages.SelectedIndex - 1); RefreshTTImages(); Overlay.Refresh(); } }; btnMoveDownTTImage.Click += (_, __) => { if (lbTTImages.SelectedIndex < lbTTImages.Items.Count - 1) { SwapImages(lbTTImages.SelectedIndex, lbTTImages.SelectedIndex + 1); RefreshTTImages(); Overlay.Refresh(); } }; var SceneContext = new ContextMenu(); SceneContext.MenuItems.Add("New", (_, __) => { if (MainForm.Project == null) { return; } using (var f = new frmScene(MainForm.Project.Scenes.ToArray())) { if (f.ShowDialog() == DialogResult.OK) { MainForm.Project.Scenes.Add(f.Result); RefreshScenes(); lbScenes.SelectedIndex = lbScenes.Items.Count - 1; } } }); SceneContext.MenuItems.Add("Edit", (_, __) => { if (MainForm.Project == null || lbScenes.SelectedItem == null) { return; } using (var f = new frmScene(MainForm.Project.Scenes.ToArray(), MainForm.Project.Scenes[lbScenes.SelectedIndex])) { if (f.ShowDialog() == DialogResult.OK) { var s = MainForm.Project.Scenes[lbScenes.SelectedIndex]; s.Name = f.Result.Name; s.ResolutionDPI = f.Result.ResolutionDPI; s.CanvasSize = f.Result.CanvasSize; RefreshScenes(); } } }); lbScenes.ContextMenu = SceneContext; lbOids.SelectedIndexChanged += LbOids_SelectedIndexChanged; lbScenes.SelectedIndexChanged += LB_Scenes_SelectedIndexChanged; tsPolygons.SelectedIndexChanged += (_, __) => { if (selectedSceneOid != null) { int i = tsPolygons.SelectedIndex; if (i > -1 && selectedSceneOid.Polygons.Count > 0) { selectedpolygon = selectedSceneOid.Polygons[i]; Overlay.Refresh(); } } }; btnOnSwitchOid.Click += (_, __) => { if (selectedScene == null) { return; } lbOids.SelectedIndex = -1; tsPolygons.Items.Clear(); if (selectedScene.StartOid == null) { selectedScene.StartOid = new SceneOid("os_start"); selectedSceneOid = selectedScene.StartOid; } if (selectedScene.StartOid.Polygons == null || selectedScene.StartOid.Polygons.Count == 0) { selectedSceneOid = selectedScene.StartOid; tsAddPoly.PerformClick(); } selectedSceneOid = selectedScene.StartOid; tsPolygons.Items.AddRange(selectedSceneOid.Polygons.ToArray()); if (tsPolygons.Items.Count > 0) { tsPolygons.SelectedIndex = 0; } }; RefreshScenes(); RefreshNodes(); tsImgMove.PerformClick(); }