neongm

Untitled

Nov 10th, 2020
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.58 KB | None | 0 0
  1. #pragma once
  2. #include <math.h>
  3. #include <string>
  4. #include <vector>
  5. #include <msclr\marshal_cppstd.h>
  6. namespace laba418 {
  7.  
  8.     using namespace System;
  9.     using namespace System::ComponentModel;
  10.     using namespace System::Collections;
  11.     using namespace System::Windows::Forms;
  12.     using namespace System::Data;
  13.     using namespace System::Drawing;
  14.     int point1[4];
  15.     int point2[4];
  16.     int point3[4];
  17.     /// <summary>
  18.     /// Сводка для MyForm
  19.     /// </summary>
  20.     public ref class MyForm : public System::Windows::Forms::Form
  21.     {
  22.     public:
  23.         MyForm(void)
  24.         {
  25.             InitializeComponent();
  26.             //
  27.             //TODO: добавьте код конструктора
  28.             //
  29.         }
  30.  
  31.     protected:
  32.         /// <summary>
  33.         /// Освободить все используемые ресурсы.
  34.         /// </summary>
  35.         ~MyForm()
  36.         {
  37.             if (components)
  38.             {
  39.                 delete components;
  40.             }
  41.         }
  42.     private: System::Windows::Forms::Button^ button1;
  43.     private: System::Windows::Forms::PictureBox^ pictureBox1;
  44.     private: System::Windows::Forms::NumericUpDown^ numericUpDown1;
  45.     private: System::Windows::Forms::ListBox^ listBox1;
  46.     private: System::Windows::Forms::Label^ label1;
  47.     protected:
  48.  
  49.     private:
  50.         /// <summary>
  51.         /// Обязательная переменная конструктора.
  52.         /// </summary>
  53.         System::ComponentModel::Container ^components;
  54.  
  55. #pragma region Windows Form Designer generated code
  56.         /// <summary>
  57.         /// Требуемый метод для поддержки конструктора — не изменяйте
  58.         /// содержимое этого метода с помощью редактора кода.
  59.         /// </summary>
  60.         void InitializeComponent(void)
  61.         {
  62.             this->button1 = (gcnew System::Windows::Forms::Button());
  63.             this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
  64.             this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
  65.             this->listBox1 = (gcnew System::Windows::Forms::ListBox());
  66.             this->label1 = (gcnew System::Windows::Forms::Label());
  67.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
  68.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->BeginInit();
  69.             this->SuspendLayout();
  70.             //
  71.             // button1
  72.             //
  73.             this->button1->Location = System::Drawing::Point(13, 8);
  74.             this->button1->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
  75.             this->button1->Name = L"button1";
  76.             this->button1->Size = System::Drawing::Size(74, 30);
  77.             this->button1->TabIndex = 0;
  78.             this->button1->Text = L"draw";
  79.             this->button1->UseVisualStyleBackColor = true;
  80.             this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  81.             //
  82.             // pictureBox1
  83.             //
  84.             this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
  85.             this->pictureBox1->Location = System::Drawing::Point(13, 45);
  86.             this->pictureBox1->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
  87.             this->pictureBox1->Name = L"pictureBox1";
  88.             this->pictureBox1->Size = System::Drawing::Size(256, 256);
  89.             this->pictureBox1->TabIndex = 1;
  90.             this->pictureBox1->TabStop = false;
  91.             this->pictureBox1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::pictureBox1_Paint);
  92.             //
  93.             // numericUpDown1
  94.             //
  95.             this->numericUpDown1->Font = (gcnew System::Drawing::Font(L"Segoe UI Light", 11.8F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  96.                 static_cast<System::Byte>(204)));
  97.             this->numericUpDown1->Location = System::Drawing::Point(95, 9);
  98.             this->numericUpDown1->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
  99.             this->numericUpDown1->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 259, 0, 0, 0 });
  100.             this->numericUpDown1->Name = L"numericUpDown1";
  101.             this->numericUpDown1->Size = System::Drawing::Size(74, 28);
  102.             this->numericUpDown1->TabIndex = 2;
  103.             //
  104.             // listBox1
  105.             //
  106.             this->listBox1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
  107.             this->listBox1->FormattingEnabled = true;
  108.             this->listBox1->ItemHeight = 17;
  109.             this->listBox1->Location = System::Drawing::Point(277, 45);
  110.             this->listBox1->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
  111.             this->listBox1->Name = L"listBox1";
  112.             this->listBox1->Size = System::Drawing::Size(256, 257);
  113.             this->listBox1->TabIndex = 3;
  114.             //
  115.             // label1
  116.             //
  117.             this->label1->AutoSize = true;
  118.             this->label1->Location = System::Drawing::Point(177, 13);
  119.             this->label1->Name = L"label1";
  120.             this->label1->Size = System::Drawing::Size(135, 19);
  121.             this->label1->TabIndex = 4;
  122.             this->label1->Text = L"- длинна стороны a ";
  123.             //
  124.             // MyForm
  125.             //
  126.             this->AutoScaleDimensions = System::Drawing::SizeF(7, 17);
  127.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  128.             this->ClientSize = System::Drawing::Size(550, 319);
  129.             this->Controls->Add(this->label1);
  130.             this->Controls->Add(this->listBox1);
  131.             this->Controls->Add(this->numericUpDown1);
  132.             this->Controls->Add(this->pictureBox1);
  133.             this->Controls->Add(this->button1);
  134.             this->Font = (gcnew System::Drawing::Font(L"Segoe UI Light", 10, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  135.                 static_cast<System::Byte>(204)));
  136.             this->Margin = System::Windows::Forms::Padding(4, 4, 4, 4);
  137.             this->Name = L"MyForm";
  138.             this->Text = L"4.18";
  139.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
  140.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown1))->EndInit();
  141.             this->ResumeLayout(false);
  142.             this->PerformLayout();
  143.  
  144.         }
  145. #pragma endregion
  146.         void DebugHandler(std::string message) {
  147.             listBox1->Items->Insert(listBox1->Items->Count, cs(message));
  148.         }void DebugHandler(String^ message) {
  149.             listBox1->Items->Insert(listBox1->Items->Count, message);
  150.         }
  151.         template<typename T>
  152.         void DebugVector(std::vector<T> vec, std::string message) {
  153.             listBox1->Items->Insert(listBox1->Items->Count, cs(message + " ["));
  154.             for (size_t i = 0; i < vec.size(); i++) listBox1->Items->Insert(listBox1->Items->Count, cs("    " + s(vec.at(i))));
  155.             listBox1->Items->Insert(listBox1->Items->Count, cs("]"));
  156.         }
  157.         int decToInt(const System::Decimal& dec) {
  158.             return dec.ToInt32(dec); // работает, лол
  159.         }
  160.         // converts System::String to std::string
  161.         std::string s(String^ str) {
  162.             return msclr::interop::marshal_as<std::string>(str);
  163.         }std::string s(System::Decimal dec) {
  164.             return std::to_string(decToInt(dec));
  165.         }template<typename T>
  166.             std::string s(const T& value) {  // converts ints, floats and anything it can to std::string
  167.             return std::to_string(value);
  168.         }
  169.         // converts std::string to System::String^
  170.         System::String^ cs(std::string str) {
  171.             return gcnew String(str.c_str());
  172.         }
  173.  
  174.  
  175.  
  176.  
  177.  
  178.     private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  179.         int a = Convert::ToInt32(numericUpDown1->Value);
  180.         DebugHandler("side a length:"+s(a));
  181.         int m = int(a / 2); //x для нижней вершины
  182.         int h = m * sin(60*(3.1415926535/180))*2; //y для нижней вершины
  183.         DebugHandler("sin60 = " + s(sin(60 * (3.1415926535 / 180))));
  184.         int PictureBoxSize = 256;
  185.         int transposeY = PictureBoxSize/2-h/2;
  186.         DebugHandler("transposeY = " + s(transposeY));
  187.         int transposeX = PictureBoxSize/2-m;
  188.         DebugHandler("transposeX = " + s(transposeX));
  189.         //координаты расположены в порядке x1y1x2y2
  190.         point1[0] = 0 + transposeX;
  191.         point1[1] = 0 + transposeY;
  192.         point1[2] = a + transposeX;
  193.         point1[3] = 0 + transposeY;
  194.         DebugHandler("line 1:  x1="+s(point1[0])+" y1="+s(point1[1])+"    x2="+s(point1[2]) + " y2=" + s(point1[3]));
  195.         point2[0] = a + transposeX;
  196.         point2[1] = 0 + transposeY;
  197.         point2[2] = m + transposeX;
  198.         point2[3] = h + transposeY;
  199.         DebugHandler("line 2:  x1=" + s(point2[0]) + " y1=" + s(point2[1]) + "    x2=" + s(point2[2]) + " y2=" + s(point2[3]));
  200.         point3[0] = m + transposeX;
  201.         point3[1] = h + transposeY;
  202.         point3[2] = 0 + transposeX;
  203.         point3[3] = 0 + transposeY;
  204.         DebugHandler("line 3:  x1=" + s(point3[0]) + " y1=" + s(point3[1]) + "    x2=" + s(point3[2]) + " y2=" + s(point3[3]));
  205.        
  206.         pictureBox1->Refresh();
  207.     }
  208.     private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
  209.         e->Graphics->DrawLine(System::Drawing::Pens::Blue, point1[0], point1[1], point1[2], point1[3]);
  210.         e->Graphics->DrawLine(System::Drawing::Pens::Green, point2[0], point2[1], point2[2], point2[3]);
  211.         e->Graphics->DrawLine(System::Drawing::Pens::Red, point3[0], point3[1], point3[2], point3[3]);
  212.     }
  213.     };
  214. }
  215.  
Advertisement
Add Comment
Please, Sign In to add comment