/// <summary>
 /// Sets up so clicking the image opens a window to view it fully.
 /// </summary>
 private void SetHandlers()
 {
     //Displays an image browsing dialog on click.
     MouseUp += new MouseButtonEventHandler((a, b) =>
     {
         DlgImgDisplay gui = new DlgImgDisplay();
         gui.Add(ImgUrl);
         gui.Show();
     });
 }
示例#2
0
        /// <summary>
        /// Sets the page content based on existing material.
        /// </summary>
        public void ConstructPage()
        {
            gui = new PgDatabaseGuiEdit();
            DataItem dat = Project.GetDatabase();

            #region Database name
            //Sets the database name.
            if (string.IsNullOrWhiteSpace((string)dat.GetData("name")))
            {
                gui.TxtblkDatabaseName.Text = GlobalStrings.NameUntitled;
            }
            else
            {
                gui.TxtblkDatabaseName.Text = (string)dat.GetData("name");
            }

            //Handles changes to the database name.
            gui.TxtblkDatabaseName.TextChanged += new TextChangedEventHandler((a, b) =>
            {
                if (!string.IsNullOrWhiteSpace(gui.TxtblkDatabaseName.Text))
                {
                    dat.SetData("name", gui.TxtblkDatabaseName.Text);
                }

                //If the textbox is empty, it will keep the last character.
                gui.TxtblkDatabaseName.Text = (string)dat.GetData("name");

                DataNameChanged?.Invoke(this, null);
            });
            #endregion

            #region Mode combobox
            //Sets the mode combobox.
            if ((bool)dat.GetData("defUseEditMode"))
            {
                gui.CmbxDefaultEditMode.SelectedValue =
                    GlobalStrings.DatabaseEditDefEditModeEdit;
            }
            else
            {
                gui.CmbxDefaultEditMode.SelectedValue =
                    GlobalStrings.DatabaseEditDefEditModeView;
            }

            //Handles changes to mode combobox.
            gui.CmbxDefaultEditMode.SelectionChanged +=
                new SelectionChangedEventHandler((a, b) =>
            {
                dat.SetData("defUseEditMode",
                            (string)gui.CmbxDefaultEditMode.SelectedValue ==
                            GlobalStrings.DatabaseEditDefEditModeEdit);
            });
            #endregion

            #region Description
            //Sets the description.
            gui.TxtbxDescription.Text = (string)dat.GetData("description");

            //Handles changes to the description.
            gui.TxtbxDescription.TextChanged += new TextChangedEventHandler((a, b) =>
            {
                dat.SetData("description", gui.TxtbxDescription.Text);
            });
            #endregion

            #region Background image
            //Sets the background image data.
            string bgUrl = (string)dat.GetData("imageUrl");
            if (!string.IsNullOrWhiteSpace(bgUrl))
            {
                if (File.Exists(bgUrl))
                {
                    gui.ImgDeleteBgImage.IsEnabled  = true;
                    gui.ImgDeleteBgImage.Visibility = Visibility.Visible;
                    gui.ImgBgImage.IsEnabled        = true;
                    gui.ImgBgImage.Visibility       = Visibility.Visible;
                    gui.ImgBgImage.Source           =
                        new BitmapImage(new Uri(bgUrl, UriKind.Absolute));
                }
                else
                {
                    gui.ImgDeleteBgImage.IsEnabled  = false;
                    gui.ImgDeleteBgImage.Visibility = Visibility.Collapsed;
                    gui.ImgBgImage.IsEnabled        = false;
                    gui.ImgBgImage.Visibility       = Visibility.Collapsed;
                }
            }
            else
            {
                gui.ImgDeleteBgImage.IsEnabled  = false;
                gui.ImgDeleteBgImage.Visibility = Visibility.Collapsed;
                gui.ImgBgImage.Visibility       = Visibility.Collapsed;
                gui.ImgBgImage.IsEnabled        = false;
            }

            //The deletion button responds to mouse interaction.
            gui.ImgDeleteBgImage.MouseEnter +=
                new System.Windows.Input.MouseEventHandler((a, b) =>
            {
                gui.ImgDeleteBgImage.Source = new BitmapImage(
                    new Uri(Assets.BttnDeleteHover));
            });

            gui.ImgDeleteBgImage.MouseLeave +=
                new System.Windows.Input.MouseEventHandler((a, b) =>
            {
                gui.ImgDeleteBgImage.Source = new BitmapImage(
                    new Uri(Assets.BttnDelete));
            });

            gui.ImgDeleteBgImage.MouseDown +=
                new System.Windows.Input.MouseButtonEventHandler((a, b) =>
            {
                dat.SetData("imageUrl", String.Empty);
                gui.ImgDeleteBgImage.IsEnabled  = false;
                gui.ImgDeleteBgImage.Visibility = Visibility.Collapsed;
                gui.ImgBgImage.IsEnabled        = false;
                gui.ImgBgImage.Visibility       = Visibility.Collapsed;

                BgImageChanged?.Invoke(this, null);
            });

            //Shows the background image in full size if clicked.
            gui.ImgBgImage.MouseDown +=
                new System.Windows.Input.MouseButtonEventHandler((a, b) =>
            {
                DlgImgDisplay gui = new DlgImgDisplay();
                gui.Add(bgUrl);
                gui.Show();
            });

            //Allows the user to browse to an image if selected.
            gui.BttnBrowseBgImage.Click +=
                new RoutedEventHandler((a, b) =>
            {
                OpenFileDialog dlg  = new OpenFileDialog();
                dlg.CheckPathExists = true;
                dlg.Filter          = GlobalStrings.FilterPictures;
                dlg.Title           = GlobalStrings.CaptionLoadDatabase;

                dlg.FileOk +=
                    new System.ComponentModel.CancelEventHandler((c, d) =>
                {
                    try
                    {
                        bgUrl = dlg.FileName;

                        gui.ImgBgImage.Source = new BitmapImage(
                            new Uri(bgUrl, UriKind.Absolute));

                        dat.SetData("imageUrl", bgUrl);

                        gui.ImgDeleteBgImage.IsEnabled  = true;
                        gui.ImgDeleteBgImage.Visibility = Visibility.Visible;
                        gui.ImgBgImage.IsEnabled        = true;
                        gui.ImgBgImage.Visibility       = Visibility.Visible;

                        BgImageChanged?.Invoke(this, null);
                    }
                    catch (NotSupportedException e)
                    {
                        Utils.Log("Uploaded non-image: " + e);
                        MessageBox.Show(GlobalStrings.DlgUploadImageError);
                    }
                });

                dlg.ShowDialog();
            });
            #endregion

            //Sets up delay between autosaves options.
            gui.TxtbxAutosaveNumSeconds.Text         = (((int)dat.GetData("autosaveDelay")) / 1000).ToString();
            gui.TxtbxAutosaveNumSeconds.TextChanged += TxtbxAutosaveNumSeconds_TextChanged;

            //Sets up delay between autosaves options.
            gui.TxtbxAutosaveNumBackups.Text         = ((int)dat.GetData("autosaveNumberofBackups")).ToString();
            gui.TxtbxAutosaveNumBackups.TextChanged += TxtbxAutosaveNumBackups_TextChanged;
        }
        /// <summary>
        /// Sets up default display behaviors.
        /// </summary>
        private void SetHandlers(bool doAutoplay)
        {
            if (doAutoplay)
            {
                Play();

                MouseUp += new MouseButtonEventHandler((a, b) =>
                {
                    ReleaseMouseCapture();
                    mouseIsDown = false;

                    Play();
                });
            }
            else
            {
                MouseUp += new MouseButtonEventHandler((a, b) =>
                {
                    ReleaseMouseCapture();
                    mouseIsDown = false;

                    if (IsMouseOver)
                    {
                        Play();
                    }
                    else
                    {
                        Stop();
                    }
                });

                MouseLeave += new MouseEventHandler((a, b) =>
                {
                    Stop();
                });

                MouseEnter += new MouseEventHandler((a, b) =>
                {
                    Play();
                });
            }

            //Displays an image browsing dialog of each frame on click.
            MouseUp += new MouseButtonEventHandler((a, b) =>
            {
                if (mouseIsClicking)
                {
                    DlgImgDisplay gui = new DlgImgDisplay();

                    for (int i = 0; i < imgUrls.Count; i++)
                    {
                        gui.Add(imgUrls[i]);
                    }

                    gui.Show();
                }
            });

            //Sets up to handle frame rotation or clicking.
            MouseDown += new MouseButtonEventHandler((a, b) =>
            {
                CaptureMouse();     //To handle mouse up while outside control.
                mouseIsDown     = true;
                mouseDownPos    = Mouse.GetPosition(this);
                mouseIsClicking = true;

                Stop();
            });

            //Controls frame rotation.
            MouseMove += new MouseEventHandler((a, b) =>
            {
                if (mouseIsDown)
                {
                    double distance =
                        Mouse.GetPosition(this).X - mouseDownPos.X;

                    if (Math.Abs(distance) >= 3)
                    {
                        if (distance >= 3)
                        {
                            NextImage();
                            mouseDownPos = Mouse.GetPosition(this);
                        }
                        else if (distance <= -3)
                        {
                            PrevImage();
                            mouseDownPos = Mouse.GetPosition(this);
                        }

                        //If a frame rotates, it's not a click.
                        mouseIsClicking = false;
                    }
                }
            });
        }