Exemple #1
0
        /// <summary>Handles the process of re-linking an already existing User in this UserTrace to a new parent</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LinkButton_Click(object sender, EventArgs e)
        {
            if (GetSelectedIndex() == -1)
            {
                return;
            }

            if (MyTrace.AllUsers[GetSelectedIndex()].Equals(MyTrace.RootUser))
            {
                MessageBox.Show("You cannot re-link the Root User.", "no", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            UserLinkerForm Linker = new UserLinkerForm(MyTrace.AllUsers[GetSelectedIndex()], MyTrace.AllUsers);

            if (Linker.ShowDialog() != DialogResult.OK)
            {
                PreviewPictureBox.Refresh(); return;
            }


            //find the parent and link it.
            //Delink the user from the old parent
            MyTrace.AllUsers[GetSelectedIndex()].Parent?.RemoveChild(MyTrace.AllUsers[GetSelectedIndex()]);
            MyTrace.AllUsers[GetSelectedIndex()].Parent = null;

            //Link the new parent.
            MyTrace.AllUsers[GetSelectedIndex()].Parent = MyTrace.AllUsers[Linker.ListIndex];
            MyTrace.AllUsers[Linker.ListIndex].AddChild(MyTrace.AllUsers[GetSelectedIndex()]);
            GeneratePreview();
            PopulateListview();
            Modified = true;
        }
Exemple #2
0
        //-[Buttons]------------------------------------------------------------------------------------------------------------------------------------------

        //You know maybe all of this logic should've been put *in* the UserTrace object.... oh well. It works, so it works

        /// <summary>Handles the adding of a new user to the UserTrace</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddButton_Click(object sender, EventArgs e)
        {
            User NewUser = new User();

            if (MyTrace.AllUsers.Count == 0)
            {
                MessageBox.Show("Since this is the first user, this will be the root user.\n\nThis can be changed later, but you may lose users before the root user if you save", "Root User Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if ("TRC".Equals(sender) || AddUnder())
                {
                    if (GetSelectedIndex() == -1)
                    {
                        return;
                    }
                    NewUser.Parent = MyTrace.AllUsers[GetSelectedIndex()];
                }
                else
                {
                    UserLinkerForm Linker = new UserLinkerForm(NewUser, MyTrace.AllUsers);
                    if (Linker.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    NewUser.Parent = MyTrace.AllUsers[Linker.ListIndex];
                    PreviewPictureBox.Refresh();
                }
            }


            UserForm TheForm = new UserForm(NewUser);

            if (TheForm.ShowDialog() != DialogResult.OK)
            {
                PreviewPictureBox.Refresh();  return;
            }

            while (MyTrace.AllUsers.Contains(NewUser))
            {
                MessageBox.Show("A user with the name " + NewUser.Name + " already exists! Please use a different name.", "Two people?", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (TheForm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }


            NewUser = TheForm.MyUser;
            if (MyTrace.AllUsers.Count == 0)
            {
                MyTrace.RootUser = NewUser;
            }
            MyTrace.AllUsers.Add(NewUser);
            NewUser.Parent?.AddChild(NewUser);

            GeneratePreview();
            PopulateListview();
        }
Exemple #3
0
        /// <summary>Handles the editing of an already existing User in the UserTrace</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditButton_Click(object sender, EventArgs e)
        {
            if (GetSelectedIndex() == -1)
            {
                return;
            }

            UserForm TheForm = new UserForm(MyTrace.AllUsers[GetSelectedIndex()]);

            if (TheForm.ShowDialog() != DialogResult.OK)
            {
                PreviewPictureBox.Refresh(); return;
            }

            MyTrace.AllUsers[GetSelectedIndex()] = TheForm.MyUser;
            GeneratePreview();
            PopulateListview();
            Modified = true;
        }
Exemple #4
0
        /// <summary>Handles the process of removing a user from the UserTrace</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            if (GetSelectedIndex() == -1)
            {
                return;
            }

            if (MyTrace.AllUsers[GetSelectedIndex()].Equals(MyTrace.RootUser))
            {
                MessageBox.Show("You cannot delete the Root User.", "no", MessageBoxButtons.OK, MessageBoxIcon.Error);
                PreviewPictureBox.Refresh();
                return;
            }

            User         D = MyTrace.AllUsers[GetSelectedIndex()];
            DialogResult T = MessageBox.Show("Are you sure you want to delete user " + D.Name + "?\n\n All of its children will be moved to " + D.Name + "'s Parent (" + D.Parent.Name + ")", "Sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (T != DialogResult.Yes)
            {
                PreviewPictureBox.Refresh(); return;
            }

            int ParentIndex = MyTrace.AllUsers.IndexOf(D.Parent);

            foreach (User orphan in D.Children)
            {
                int OrphanIndex = MyTrace.AllUsers.IndexOf(orphan);
                MyTrace.AllUsers[ParentIndex].AddChild(MyTrace.AllUsers[OrphanIndex]);
                MyTrace.AllUsers[OrphanIndex].Parent = MyTrace.AllUsers[ParentIndex];
            }

            MyTrace.AllUsers[ParentIndex].RemoveChild(D);
            MyTrace.AllUsers.Remove(D);

            GeneratePreview();
            PopulateListview();
            Modified = true;
        }
Exemple #5
0
        /// <summary>Handles creating a previewform for the UserTrace image and its big big subroutine</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PreviewPictureBox_Click(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right && e.Button != MouseButtons.Left)
            {
                return;
            }

            fromPreviewPane = true;

            //If the usertrace is empty, just show it anyways.
            if (MyTrace.AllUsers.Count == 0 && e.Button == MouseButtons.Right)
            {
                UsersContextMenu.Show(PreviewPictureBox, e.Location); fromPreviewPane = false; return;
            }

            //Let's find the top right corner of the image.
            Size ImageSize     = PreviewPictureBox.Image.Size;
            Size BoxSize       = PreviewPictureBox.Size;
            Size RealImageSize = PreviewPictureBox.Size;

            int    PictureX = 0;
            int    PictureY = 0;
            double scale    = 1;

            //Get the aspect ratio of the picturebox and image.
            double BoxWidthToHeight   = (BoxSize.Width + 0.0) / (BoxSize.Height + 0.0);
            double ImageWidthToHeight = (ImageSize.Width + 0.0) / (ImageSize.Height + 0.0);

            if (ImageSize.Equals(BoxSize))
            {
                //do nothing the thing is set.
            }
            else if (ImageWidthToHeight > BoxWidthToHeight)
            {
                //Find the correct Y
                //It's wider than it's tall

                //determine the scale
                scale = (ImageSize.Width + 0.0) / (BoxSize.Width + 0.0);

                //Determine the size of the image on screen
                RealImageSize = new Size(Convert.ToInt32(ImageSize.Width / scale), Convert.ToInt32(ImageSize.Height / scale));

                //Now determine the correct Y
                PictureY = (BoxSize.Height - RealImageSize.Height) / 2;
            }
            else
            {
                //It's taller than it's wide
                //find the correct X

                //Determine the scale
                scale = (ImageSize.Height + 0.0) / (BoxSize.Height + 0.0);

                //Determine the size of the image on screen
                RealImageSize = new Size(Convert.ToInt32(ImageSize.Width / scale), Convert.ToInt32(ImageSize.Height / scale));

                //Now determine the correct X
                PictureX = (BoxSize.Width - RealImageSize.Width) / 2;
            }

            //OK now that we know where the picture is and its size.
            //Now we have to translate the point that we clicked on to a point on the image.
            //first lets determine if we're in or out of the rectangle that contains the image.
            Rectangle ImageRectangle = new Rectangle(PictureX, PictureY, RealImageSize.Width, RealImageSize.Height);

            //If it isn't then oh my god we've literally done everything
            if (!ImageRectangle.Contains(e.Location))
            {
                fromPreviewPane = false; return;
            }

            //Convert
            //subtract PictureX and Picture Y from the click position.
            int ClickPointX = e.X - PictureX;
            int ClickPointY = e.Y - PictureY;

            //now scale it.
            ClickPointX = Convert.ToInt32(ClickPointX * scale);
            ClickPointY = Convert.ToInt32(ClickPointY * scale);

            User ColideUser = null;

            foreach (User U in MyTrace.AllUsers)
            {
                //Create a rectangle that's going to represent this user.
                if (new Rectangle(U.DrawnX, U.DrawnY, U.Width(), U.Height()).Contains(ClickPointX, ClickPointY))
                {
                    ColideUser = U;
                    break;
                }
            }

            if (!(ColideUser is null))
            {
                //lets draw algo:
                using (Pen T = new Pen(new SolidBrush(Color.Red), 10))
                    using (Graphics GRD = Graphics.FromImage(PreviewPictureBox.Image)) { GRD.DrawRectangle(T, ColideUser.DrawnX, ColideUser.DrawnY, ColideUser.Width(), ColideUser.Height()); }
                PreviewPictureBox.Refresh();
                using (Pen T = new Pen(new SolidBrush(Color.Black), 10))
                    using (Graphics GRD = Graphics.FromImage(PreviewPictureBox.Image)) { GRD.DrawRectangle(T, ColideUser.DrawnX, ColideUser.DrawnY, ColideUser.Width(), ColideUser.Height()); }

                UserListView.Items[MyTrace.AllUsers.IndexOf(ColideUser)].Selected = true;
                if (e.Button == MouseButtons.Left)
                {
                    EditButton_Click(PreviewPictureBox, new EventArgs());
                }
                if (e.Button == MouseButtons.Right)
                {
                    UsersContextMenu.Show(PreviewPictureBox, e.Location);
                }
            }