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

namespace ColorSpaces
{
	public partial class MainForm : Form
	{
		public MainForm()
		{
			InitializeComponent();
		}

        private void rgb_ValueChanged(object sender, EventArgs e)
        {
            Color rgb = Color.FromArgb((int)red.Value,(int)green.Value,(int)blue.Value);
            colorPanel.BackColor = rgb;
            UpdateCMYK(new CMYK(rgb));
            UpdateHSB(new HSB(rgb));
			UpdateCMY(new CMY(rgb));
		}

        private void UpdateCMYK(CMYK cmyk)
        {
  			cmykLabel.Text = cmyk.ToString();
        }

		private void UpdateCMY(CMY cmy)
		{
			cyan.Value = cmy.C;
			magenta.Value = cmy.M;
			yellow.Value = cmy.Y;
		}

        private void UpdateHSB(HSB hsb)
        {
            hue.Text = hsb.H.ToString();
            saturation.Text = hsb.S.ToString();
            brightness.Text = hsb.B.ToString();
        }

        private void UpdateRGB(Color rgb)
        {
            red.Value = rgb.R;
            green.Value = rgb.G;
            blue.Value = rgb.B;
        }

        private void cmyk_ValueChanged(object sender, EventArgs e)
        {
            CMY cmy = new CMY((byte)cyan.Value, (byte)magenta.Value, (byte)yellow.Value);
			CMYK cmyk = new CMYK(cmy); 
			Color rgb = cmyk; // Неявное преобразование
            UpdateRGB(rgb);
            UpdateHSB(new HSB(rgb));
			UpdateCMYK(cmyk);
        }

		private void MainForm_Load(object sender, EventArgs e)
		{
			CMY cmy = new CMY((byte)cyan.Value, (byte)magenta.Value, (byte)yellow.Value);
			CMYK cmyk = new CMYK(cmy);
			cmykLabel.Text = cmyk.ToString();
		}
	}
}