private void ChangeAnimationType_Select(object sender, EventArgs e) { var selectedType = cmbAnimationType.SelectedItem?.ToString(); gpAnimationDrawing.Visible = false; gpAnimationImage.Visible = false; gpAnimationActionMoveX.Visible = false; if (!populatingForm) { IAnimationItem newAnimation = null; if (selectedType == "Drawing") { newAnimation = new AnimationDrawing { Name = _animation.Name, Type = AnimationItemTypeEnum.Drawing, FillColor = Color.White, FillMethod = FillTypeEnum.Solid, OffsetX = 50, OffsetY = 50, Triggers = _animation.Triggers }; } if (selectedType == "Image") { newAnimation = new AnimationImage { Name = _animation.Name, Type = AnimationItemTypeEnum.Image, ImagePath = "", Triggers = _animation.Triggers }; pbAnimationImage.BackgroundImage?.Dispose(); pbAnimationImage.BackgroundImage = new Bitmap(1, 1); pbAnimationImage.Image?.Dispose(); pbAnimationImage.Image = new Bitmap(1, 1); } _animation = newAnimation; PopulateTab(0); } //if (_animation.Type == AnimationItemTypeEnum.Image) //{ // gpAnimationImage.Visible = true; //} //if(_animation.Type == AnimationItemTypeEnum.Drawing) //{ // gpAnimationDrawing.Visible = true; //} }
private Bitmap DrawPoints(AnimationDrawing animation) { try { if (animation.PointMap?.Count() > 0) { float absoluteX = 0; float absoluteY = 0; // Resize animation image to fit the current control size var scaleX = animation.OffsetX / 100.0f; var scaleY = animation.OffsetY / 100.0f; // Points can be between -100% to +100% (a range of 200%)- Therefore we assume 1 percent of control is actually 0.5 percent var pixelsPerPercentX = Control.Width / 200.0f; var pixelsPerPercentY = Control.Height / 200.0f; absoluteX = (float)(Control.Width * scaleX); absoluteY = (float)(Control.Height * scaleY); var points = animation.PointMap.Select(x => new PointF(x.Point.X * pixelsPerPercentX + absoluteX, x.Point.Y * pixelsPerPercentY + absoluteY)).ToArray(); Bitmap bitmap = new Bitmap(Control.Width, Control.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); bitmap.MakeTransparent(); using (Graphics graph = Graphics.FromImage(bitmap)) { graph.SmoothingMode = SmoothingMode.AntiAlias; graph.InterpolationMode = InterpolationMode.HighQualityBicubic; graph.PixelOffsetMode = PixelOffsetMode.HighQuality; using (SolidBrush fill = new SolidBrush(animation.FillColor)) { graph.FillPolygon(fill, points); } } return(bitmap); } } catch (Exception ex) { WriteLog("DrawPoints: Failed to generate image from PointMap.", ex); } return(null); }
private void EditDeleteAnimation_Click(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (e.ColumnIndex >= 0 && senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { var action = senderGrid.Columns[e.ColumnIndex].HeaderText?.ToString(); var name = senderGrid.Rows[e.RowIndex].Cells["What"].Value?.ToString(); Form frm; DialogResult result = DialogResult.Abort; switch (action) { case "E": if (config.Animations == null || !config.Animations.Any(x => ((IAnimationItem)x).Name == name)) { var newAnimation = new AnimationDrawing { Name = name, Type = AnimationItemTypeEnum.Drawing, Triggers = new IAnimationTrigger[0] }; newAnimation.Triggers.ToList().Add( (IAnimationTrigger) new AnimationTriggerClientRequest { Type = AnimationTriggerTypeEnum.ClientRequest, Actions = new IAnimationAction[0] }); config.Animations = new IAnimationItem[0];; config.Animations.ToList().Add(newAnimation); } var animation = ObjectClone.Clone <IAnimationItem>((IAnimationItem)config.Animations.First(x => ((IAnimationItem)x).Name == name)); //ObjectClone.Clone(config.Animations?.First(x => x.Name == name)); using (frm = new frmAnimation((IAnimationItem)animation, cockpitDirectory)) { result = frm.ShowDialog(this); if (result == DialogResult.OK) { var newAnimation = ((frmAnimation)frm).DialogValue; // Replace existing animation with the modified version var currentAnimations = config.Animations.ToList(); currentAnimations[currentAnimations.IndexOf(currentAnimations.First(x => ((IAnimationItem)x).Name == name))] = newAnimation; config.Animations = currentAnimations.ToArray(); } } break; case "X": result = MessageBox.Show("Are you sure you want to delete this animation?", "Delete Animation", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { var newAnimations = config.Animations.ToList(); newAnimations.RemoveAt(newAnimations.IndexOf(newAnimations.First(x => ((IAnimationItem)x).Name == name))); config.Animations = newAnimations.ToArray(); } break; } if (result == DialogResult.OK) { PopulateConfigForm(); } } }