using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace meteo
{
    public partial class fotoframe : Form
    {
        private string[] folderFile = null;
        private int selected = 0;
        private int begin = 0;
        private int end = 0;
        
        
        public fotoframe()
        {
            InitializeComponent();
        }

        private void on_load(object sender, EventArgs e)
        {
            string[] part1 = null, part2 = null, part3 = null;
            part1 = Directory.GetFiles(@"Storage Card/fotky/", "*.jpg");
            part2 = Directory.GetFiles(@"Storage Card/fotky/", "*.jpeg");
            part3 = Directory.GetFiles(@"Storage Card/fotky/", "*.bmp");
            folderFile = new string[part1.Length + part2.Length + part3.Length];
            Array.Copy(part1, 0, folderFile, 0, part1.Length);
            selected = 0;
            begin = 0;
            end = folderFile.Length;

            Image img = new Bitmap("imagenotfound.png");

            if (selected > 0)
            {
                showImage(folderFile[selected]);

            }

            else pcb1.Image = img;
        }

        private void showImage(string path)
        {
            int delka = 350;
            int sirka = 640;
            int deleni, deleni2, fin = 0;

            Image img = new Bitmap(path);
            Image imgtemp = img;
            deleni = imgtemp.Width / sirka;
            deleni2 = imgtemp.Height / delka;


            if (deleni >= deleni2) fin = deleni;
            else fin = deleni2;

            //label1.Text = (imgtemp.Width / fin).ToString();
            //label2.Text = (imgtemp.Height / fin).ToString();
            //label2.Text = pictureBox1.Location.X.ToString();

            pcb1.Left = ((sirka - (imgtemp.Width / fin)) / 2) + 12;
            //pictureBox1.Top = ((delka - (imgtemp.Height / fin)) / 2) + 12;

            //label1.Text = pictureBox1.Location.X.ToString();

            pcb1.Width = (imgtemp.Width / fin);
            pcb1.Height = (imgtemp.Height / fin);
            //if (pcb1.Width > sirka) pcb1.Width = sirka;
            //if (pcb1.Height > delka) pcb1.Height = delka;
            pcb1.Image = imgtemp;

        }

        private void bt_next_Click(object sender, EventArgs e)
        {
            next_image();
        }

        void next_image() {

            if (selected == folderFile.Length - 1)
            {
                selected = 0;
                showImage(folderFile[selected]);
            }
            else
            {
                selected = selected + 1;
                showImage(folderFile[selected]);
            }
        }

        private void bt_menu_Click_1(object sender, EventArgs e)
        {

        }

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