using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace Azyobuzi.Twirunrun
{
    public partial class PictureViewer : Form
    {
        public PictureViewer(string imgUri)
        {
            InitializeComponent();
            this.imgUri = imgUri;
        }

        string imgUri;


        private void PictureViewer_Load(object sender, EventArgs e)
        {
            checkBox1.Checked = Settings.Instance.PictureViewerAutoSize;
            Settings.Instance.ViewerForm.Restore(this);

            checkBox1_CheckedChanged(checkBox1, EventArgs.Empty);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            Settings.Instance.PictureViewerAutoSize = checkBox1.Checked;
            if (checkBox1.Checked)
            {
                PictureBox.SizeMode = PictureBoxSizeMode.Zoom;
                PictureBox.Dock = DockStyle.Fill;
            }
            else
            {
                PictureBox.Dock = DockStyle.None;
                PictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
            }
        }

        private void PictureViewer_Shown(object sender, EventArgs e)
        {
            PictureBox.LoadAsync(imgUri);
        }

        private void pictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }

        private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            progressBar1.Visible = false;
        }

        private void PictureViewer_BoundsChanged(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Normal)
                Settings.Instance.ViewerForm = FormSettings.FromForm(this);
            Settings.Instance.ViewerForm.WindowState = this.WindowState;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
