// determine build architecture
#if defined _M_IX86
#define ARCH 32
#elif defined _M_X64
#define ARCH 64
#endif

#pragma once
#include "MyFormError.h"
#include "cuda_runtime.h"

namespace Image_Segmentation_on_GPU {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for MyFormAbout
	/// </summary>
	public ref class MyFormAbout : public System::Windows::Forms::Form
	{
	public:
		MyFormAbout(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~MyFormAbout()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::PictureBox^  pictureBox_Logo;
	private: System::Windows::Forms::TableLayoutPanel^  tableLayoutPanel1;
	private: System::Windows::Forms::GroupBox^  groupBox_About;
	private: System::Windows::Forms::GroupBox^  groupBox_Info;
	private: System::Windows::Forms::LinkLabel^  linkLabel_feec_vutbr;

	private: System::Windows::Forms::LinkLabel^  linkLabel_vutbr;

	private: System::Windows::Forms::Label^  label_WWW;
	private: System::Windows::Forms::Label^  label_Author;
	private: System::Windows::Forms::Label^  label_Build;
	private: System::Windows::Forms::Label^  label_Version;


	private: System::Windows::Forms::Label^  label_CUDA_version;
	private: System::Windows::Forms::Label^  label_NET_version;
	private: System::Windows::Forms::Label^  label_email;
	private: System::Windows::Forms::LinkLabel^  linkLabel_email;
	private: System::Windows::Forms::Label^  label1;






	protected:

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(MyFormAbout::typeid));
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->pictureBox_Logo = (gcnew System::Windows::Forms::PictureBox());
			this->tableLayoutPanel1 = (gcnew System::Windows::Forms::TableLayoutPanel());
			this->groupBox_About = (gcnew System::Windows::Forms::GroupBox());
			this->label_email = (gcnew System::Windows::Forms::Label());
			this->linkLabel_email = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabel_feec_vutbr = (gcnew System::Windows::Forms::LinkLabel());
			this->linkLabel_vutbr = (gcnew System::Windows::Forms::LinkLabel());
			this->label_WWW = (gcnew System::Windows::Forms::Label());
			this->label_Author = (gcnew System::Windows::Forms::Label());
			this->groupBox_Info = (gcnew System::Windows::Forms::GroupBox());
			this->label_NET_version = (gcnew System::Windows::Forms::Label());
			this->label_CUDA_version = (gcnew System::Windows::Forms::Label());
			this->label_Build = (gcnew System::Windows::Forms::Label());
			this->label_Version = (gcnew System::Windows::Forms::Label());
			this->label1 = (gcnew System::Windows::Forms::Label());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox_Logo))->BeginInit();
			this->tableLayoutPanel1->SuspendLayout();
			this->groupBox_About->SuspendLayout();
			this->groupBox_Info->SuspendLayout();
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left)
				| System::Windows::Forms::AnchorStyles::Right));
			this->button1->DialogResult = System::Windows::Forms::DialogResult::OK;
			this->button1->Location = System::Drawing::Point(202, 199);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(80, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Close";
			this->button1->UseVisualStyleBackColor = true;
			// 
			// pictureBox_Logo
			// 
			this->pictureBox_Logo->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left)
				| System::Windows::Forms::AnchorStyles::Right));
			this->pictureBox_Logo->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox_Logo.Image")));
			this->pictureBox_Logo->Location = System::Drawing::Point(13, 13);
			this->pictureBox_Logo->Name = L"pictureBox_Logo";
			this->pictureBox_Logo->Size = System::Drawing::Size(459, 82);
			this->pictureBox_Logo->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
			this->pictureBox_Logo->TabIndex = 1;
			this->pictureBox_Logo->TabStop = false;
			// 
			// tableLayoutPanel1
			// 
			this->tableLayoutPanel1->ColumnCount = 2;
			this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
				50)));
			this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
				50)));
			this->tableLayoutPanel1->Controls->Add(this->groupBox_About, 0, 0);
			this->tableLayoutPanel1->Controls->Add(this->groupBox_Info, 1, 0);
			this->tableLayoutPanel1->Location = System::Drawing::Point(13, 102);
			this->tableLayoutPanel1->Name = L"tableLayoutPanel1";
			this->tableLayoutPanel1->RowCount = 1;
			this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 100)));
			this->tableLayoutPanel1->Size = System::Drawing::Size(459, 91);
			this->tableLayoutPanel1->TabIndex = 2;
			// 
			// groupBox_About
			// 
			this->groupBox_About->Controls->Add(this->label_email);
			this->groupBox_About->Controls->Add(this->linkLabel_email);
			this->groupBox_About->Controls->Add(this->linkLabel_feec_vutbr);
			this->groupBox_About->Controls->Add(this->linkLabel_vutbr);
			this->groupBox_About->Controls->Add(this->label_WWW);
			this->groupBox_About->Controls->Add(this->label_Author);
			this->groupBox_About->Location = System::Drawing::Point(3, 3);
			this->groupBox_About->Name = L"groupBox_About";
			this->groupBox_About->Size = System::Drawing::Size(223, 85);
			this->groupBox_About->TabIndex = 0;
			this->groupBox_About->TabStop = false;
			this->groupBox_About->Text = L"Image Segmentation on GPU";
			// 
			// label_email
			// 
			this->label_email->AutoSize = true;
			this->label_email->Location = System::Drawing::Point(11, 37);
			this->label_email->Name = L"label_email";
			this->label_email->Size = System::Drawing::Size(38, 13);
			this->label_email->TabIndex = 5;
			this->label_email->Text = L"Email: ";
			// 
			// linkLabel_email
			// 
			this->linkLabel_email->AutoSize = true;
			this->linkLabel_email->Location = System::Drawing::Point(60, 37);
			this->linkLabel_email->Name = L"linkLabel_email";
			this->linkLabel_email->Size = System::Drawing::Size(100, 13);
			this->linkLabel_email->TabIndex = 4;
			this->linkLabel_email->TabStop = true;
			this->linkLabel_email->Text = L"xbrave01@vutbr.cz";
			// 
			// linkLabel_feec_vutbr
			// 
			this->linkLabel_feec_vutbr->AutoSize = true;
			this->linkLabel_feec_vutbr->Location = System::Drawing::Point(60, 63);
			this->linkLabel_feec_vutbr->Name = L"linkLabel_feec_vutbr";
			this->linkLabel_feec_vutbr->Size = System::Drawing::Size(96, 13);
			this->linkLabel_feec_vutbr->TabIndex = 3;
			this->linkLabel_feec_vutbr->TabStop = true;
			this->linkLabel_feec_vutbr->Text = L"www.feec.vutbr.cz";
			this->linkLabel_feec_vutbr->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &MyFormAbout::linkLabel_feec_vutbr_LinkClicked);
			// 
			// linkLabel_vutbr
			// 
			this->linkLabel_vutbr->AutoSize = true;
			this->linkLabel_vutbr->Location = System::Drawing::Point(60, 50);
			this->linkLabel_vutbr->Name = L"linkLabel_vutbr";
			this->linkLabel_vutbr->Size = System::Drawing::Size(72, 13);
			this->linkLabel_vutbr->TabIndex = 2;
			this->linkLabel_vutbr->TabStop = true;
			this->linkLabel_vutbr->Text = L"www.vutbr.cz";
			this->linkLabel_vutbr->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &MyFormAbout::linkLabel_vutbr_LinkClicked);
			// 
			// label_WWW
			// 
			this->label_WWW->AutoSize = true;
			this->label_WWW->Location = System::Drawing::Point(11, 50);
			this->label_WWW->Name = L"label_WWW";
			this->label_WWW->Size = System::Drawing::Size(43, 13);
			this->label_WWW->TabIndex = 1;
			this->label_WWW->Text = L"WWW:";
			// 
			// label_Author
			// 
			this->label_Author->AutoSize = true;
			this->label_Author->Location = System::Drawing::Point(11, 24);
			this->label_Author->Name = L"label_Author";
			this->label_Author->Size = System::Drawing::Size(134, 13);
			this->label_Author->TabIndex = 0;
			this->label_Author->Text = L"Author:    Tomáš Bravenec";
			// 
			// groupBox_Info
			// 
			this->groupBox_Info->Controls->Add(this->label1);
			this->groupBox_Info->Controls->Add(this->label_NET_version);
			this->groupBox_Info->Controls->Add(this->label_CUDA_version);
			this->groupBox_Info->Controls->Add(this->label_Build);
			this->groupBox_Info->Controls->Add(this->label_Version);
			this->groupBox_Info->Location = System::Drawing::Point(232, 3);
			this->groupBox_Info->Name = L"groupBox_Info";
			this->groupBox_Info->Size = System::Drawing::Size(224, 85);
			this->groupBox_Info->TabIndex = 1;
			this->groupBox_Info->TabStop = false;
			this->groupBox_Info->Text = L"Technical Information";
			// 
			// label_NET_version
			// 
			this->label_NET_version->AutoSize = true;
			this->label_NET_version->Location = System::Drawing::Point(6, 55);
			this->label_NET_version->Name = L"label_NET_version";
			this->label_NET_version->Size = System::Drawing::Size(142, 13);
			this->label_NET_version->TabIndex = 4;
			this->label_NET_version->Text = L".NET framework version: 4.0";
			// 
			// label_CUDA_version
			// 
			this->label_CUDA_version->AutoSize = true;
			this->label_CUDA_version->Location = System::Drawing::Point(6, 42);
			this->label_CUDA_version->Name = L"label_CUDA_version";
			this->label_CUDA_version->Size = System::Drawing::Size(132, 13);
			this->label_CUDA_version->TabIndex = 2;
			this->label_CUDA_version->Text = L"CUDA runtime version: 8.0";
			// 
			// label_Build
			// 
			this->label_Build->AutoSize = true;
			this->label_Build->Location = System::Drawing::Point(6, 29);
			this->label_Build->Name = L"label_Build";
			this->label_Build->Size = System::Drawing::Size(123, 13);
			this->label_Build->TabIndex = 1;
			this->label_Build->Text = L"Build date:  24. 05. 2017";
			// 
			// label_Version
			// 
			this->label_Version->AutoSize = true;
			this->label_Version->Location = System::Drawing::Point(6, 16);
			this->label_Version->Name = L"label_Version";
			this->label_Version->Size = System::Drawing::Size(63, 13);
			this->label_Version->TabIndex = 0;
			this->label_Version->Text = L"Version: 1.0";
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(6, 69);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(120, 13);
			this->label1->TabIndex = 5;
			this->label1->Text = L"OpenCV version: 2.4.13";
			// 
			// MyFormAbout
			// 
			this->AcceptButton = this->button1;
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->CancelButton = this->button1;
			this->ClientSize = System::Drawing::Size(484, 234);
			this->Controls->Add(this->tableLayoutPanel1);
			this->Controls->Add(this->pictureBox_Logo);
			this->Controls->Add(this->button1);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
			this->Icon = (cli::safe_cast<System::Drawing::Icon^>(resources->GetObject(L"$this.Icon")));
			this->MaximizeBox = false;
			this->MinimizeBox = false;
			this->MinimumSize = System::Drawing::Size(500, 185);
			this->Name = L"MyFormAbout";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
			this->Text = L"About Image Segmentation on GPU";
			this->Load += gcnew System::EventHandler(this, &MyFormAbout::MyFormAbout_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox_Logo))->EndInit();
			this->tableLayoutPanel1->ResumeLayout(false);
			this->groupBox_About->ResumeLayout(false);
			this->groupBox_About->PerformLayout();
			this->groupBox_Info->ResumeLayout(false);
			this->groupBox_Info->PerformLayout();
			this->ResumeLayout(false);

		}
#pragma endregion


	private: System::Void MyFormAbout_Load(System::Object^  sender, System::EventArgs^  e)
	{
		// change name of About Window dependending on architecture application was build for
		switch (ARCH)
		{
		case 32:
			this->Text = "About Image Segmentation on GPU (x86)";
			break;
		case 64:
			this->Text = "About Image Segmentation on GPU (x64)";
			break;
		default:
			this->Text = "About Image Segmentation on GPU";
			break;
		}

		// change CUDA runtime depending on CUDA toolkit used for building
		int CUDA;
		cudaRuntimeGetVersion(&CUDA); //returns 4 digits long integer where 1st and third number means major and minor version
		double CUDAversion = CUDA / 1000 + System::Convert::ToDouble(CUDA - (CUDA / 100) * 100) / 100;
		this->label_CUDA_version->Text = "CUDA runtime version: " + CUDAversion;
	}

	private: System::Void linkLabel_vutbr_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e)
	{
		try
		{
			// start default web browser and open link
			this->linkLabel_vutbr->LinkVisited = true;
			System::Diagnostics::Process::Start("https://www.vutbr.cz/");
		}
		catch (Exception^ except)
		{
			// using second form as custom messagebox with window for exception code
			MyFormError^ ErrBox = gcnew MyFormError();
			ErrBox->titleText = "ERROR!";
			ErrBox->descriptionText = "This website could not be opened!";
			ErrBox->exceptionText = except->ToString();
			ErrBox->Buttons = System::Windows::Forms::MessageBoxButtons::OK;
			ErrBox->ShowDialog();
			delete ErrBox;
		}
	}
	private: System::Void linkLabel_feec_vutbr_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e)
	{
		try
		{
			// start default web browser and open link
			this->linkLabel_feec_vutbr->LinkVisited = true;
			System::Diagnostics::Process::Start("http://www.feec.vutbr.cz/");
		}
		catch (Exception^ except)
		{
			// using second form as custom messagebox with window for exception code
			MyFormError^ ErrBox = gcnew MyFormError();
			ErrBox->titleText = "ERROR!";
			ErrBox->descriptionText = "This website could not be opened!";
			ErrBox->exceptionText = except->ToString();
			ErrBox->Buttons = System::Windows::Forms::MessageBoxButtons::OK;
			ErrBox->dlgIcon = System::Drawing::SystemIcons::Error->ToBitmap();
			ErrBox->ShowDialog();
			delete ErrBox;
		}
	}
	};
}
