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

namespace iTripLog.Map.Controler
{
    public class PPTView : Control
    {
       
        Image backgroundImage;
        bool pressed = false;
        Point imageSize;
        MapBGFrom frame;

        public PPTView(MapBGFrom frame)
        {
            this.frame = frame;
            this.Size = new Size(this.frame.builder.XSize,this.frame.builder.YSize);
        }

       

        // Property for the background image to be drawn behind the button text.
        public Image BackgroundImage
        {
            get
            {
                return this.backgroundImage;
            }
            set
            {
                this.backgroundImage = value;
            }
        }

        // When the mouse button is pressed, set the "pressed" flag to true 
        // and invalidate the form to cause a repaint.  The .NET Compact Framework 
        // sets the mouse capture automatically.
        protected override void OnMouseDown(MouseEventArgs e)
        {
            this.pressed = true;
            this.BringToFront();
            frame.nextPPT();
            base.OnMouseDown(e);
        }

        protected override void OnDoubleClick(EventArgs e)
        {
            frame.StopTimer();
            base.OnDoubleClick(e);
        }
        

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.FillRectangle(new SolidBrush(SystemColors.ActiveCaption), e.ClipRectangle);

            if (this.backgroundImage != null)
            {
                System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes();
                attr.SetColorKey(Color.Magenta, Color.Magenta);
                this.BackColor = Color.Black;
                if (this.pressed)
                {
                    if (imageSize.X < imageSize.Y)
                    {
                        e.Graphics.DrawImage(this.backgroundImage, this.ClientRectangle, 0, 0, this.backgroundImage.Width, this.backgroundImage.Height, GraphicsUnit.Pixel, attr);
                    }
                    else
                    {
                        e.Graphics.DrawImage(this.backgroundImage, this.ClientRectangle, 0, (int)(frame.builder.YSize / 2 - frame.builder.XSize * 0.75) / 2, this.backgroundImage.Width, this.backgroundImage.Height, GraphicsUnit.Pixel, attr);
                    }
                }
                else
                {
                    if (imageSize.X < imageSize.Y)
                    {
                        e.Graphics.DrawImage(this.backgroundImage, this.ClientRectangle, 0, 0, this.backgroundImage.Width, this.backgroundImage.Height, GraphicsUnit.Pixel, attr);
                    }
                    else
                    {
                        e.Graphics.DrawImage(this.backgroundImage, this.ClientRectangle, 0, (int)(frame.builder.YSize / 2 - frame.builder.XSize * 0.75) / 2, this.backgroundImage.Width, this.backgroundImage.Height, GraphicsUnit.Pixel, attr);
                    }
                }
            }

            base.OnPaint(e);
        }
    }
}
