Advertisement
vesso8

kg-margaritka

Oct 15th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.67 KB | None | 0 0
  1. // KG-3VESO.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "framework.h"
  5. #include "KG-3VESO.h"
  6. #include "targetver.h"
  7.  
  8. #define MAX_LOADSTRING 100
  9.  
  10. // Global Variables:
  11. HINSTANCE hInst;                                // current instance
  12. WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  13. WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  14. VOID DRAW_Waves_and_Ship(HDC hdc, int ak, int xend, int yend);
  15. int ak = 0;
  16.  
  17. // Forward declarations of functions included in this code module:
  18. ATOM                MyRegisterClass(HINSTANCE hInstance);
  19. BOOL                InitInstance(HINSTANCE, int);
  20. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  21. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  22.  
  23. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  24.                      _In_opt_ HINSTANCE hPrevInstance,
  25.                      _In_ LPWSTR    lpCmdLine,
  26.                      _In_ int       nCmdShow)
  27. {
  28.     UNREFERENCED_PARAMETER(hPrevInstance);
  29.     UNREFERENCED_PARAMETER(lpCmdLine);
  30.  
  31.     // TODO: Place code here.
  32.     GdiplusStartupInput gdiplusStartupInput;
  33.     ULONG_PTR gdiplusToken;
  34.     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  35.  
  36.  
  37.     // Initialize global strings
  38.     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  39.     LoadStringW(hInstance, IDC_KG3VESO, szWindowClass, MAX_LOADSTRING);
  40.     MyRegisterClass(hInstance);
  41.  
  42.     // Perform application initialization:
  43.     if (!InitInstance (hInstance, nCmdShow))
  44.     {
  45.         return FALSE;
  46.     }
  47.  
  48.     HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_KG3VESO));
  49.  
  50.     MSG msg;
  51.  
  52.     // Main message loop:
  53.     while (GetMessage(&msg, nullptr, 0, 0))
  54.     {
  55.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  56.         {
  57.             TranslateMessage(&msg);
  58.             DispatchMessage(&msg);
  59.         }
  60.     }
  61.     GdiplusShutdown(gdiplusToken);
  62.     return (int) msg.wParam;
  63. }
  64.  
  65.  
  66.  
  67. //
  68. //  FUNCTION: MyRegisterClass()
  69. //
  70. //  PURPOSE: Registers the window class.
  71. //
  72. ATOM MyRegisterClass(HINSTANCE hInstance)
  73. {
  74.     WNDCLASSEXW wcex;
  75.  
  76.     wcex.cbSize = sizeof(WNDCLASSEX);
  77.  
  78.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  79.     wcex.lpfnWndProc    = WndProc;
  80.     wcex.cbClsExtra     = 0;
  81.     wcex.cbWndExtra     = 0;
  82.     wcex.hInstance      = hInstance;
  83.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_KG3VESO));
  84.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  85.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  86.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_KG3VESO);
  87.     wcex.lpszClassName  = szWindowClass;
  88.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  89.  
  90.     return RegisterClassExW(&wcex);
  91. }
  92.  
  93. //
  94. //   FUNCTION: InitInstance(HINSTANCE, int)
  95. //
  96. //   PURPOSE: Saves instance handle and creates main window
  97. //
  98. //   COMMENTS:
  99. //
  100. //        In this function, we save the instance handle in a global variable and
  101. //        create and display the main program window.
  102. //
  103. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  104. {
  105.    hInst = hInstance; // Store instance handle in our global variable
  106.  
  107.    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  108.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  109.  
  110.    if (!hWnd)
  111.    {
  112.       return FALSE;
  113.    }
  114.  
  115.    ShowWindow(hWnd, nCmdShow);
  116.    UpdateWindow(hWnd);
  117.  
  118.    return TRUE;
  119. }
  120.  
  121. //
  122. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  123. //
  124. //  PURPOSE: Processes messages for the main window.
  125. //
  126. //  WM_COMMAND  - process the application menu
  127. //  WM_PAINT    - Paint the main window
  128. //  WM_DESTROY  - post a quit message and return
  129. //
  130. //
  131. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  132. {
  133.     int wmId, wmEvent;
  134.     PAINTSTRUCT ps;
  135.     HDC hdc;
  136.     switch (message)
  137.     {
  138.     case WM_RBUTTONDOWN:
  139.     {
  140.         InvalidateRect(hWnd, NULL, false);
  141.         ak++;  (ak > 7);
  142.         ::UpdateWindow(hWnd);
  143.     }
  144.     break;
  145.     case WM_COMMAND:
  146.         {
  147.             int wmId = LOWORD(wParam);
  148.             // Parse the menu selections:
  149.             switch (wmId)
  150.             {
  151.             case IDM_ABOUT:
  152.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  153.                 break;
  154.             case IDM_EXIT:
  155.                 DestroyWindow(hWnd);
  156.                 break;
  157.             default:
  158.                 return DefWindowProc(hWnd, message, wParam, lParam);
  159.             }
  160.         }
  161.         break;
  162.     case WM_PAINT:
  163.         {
  164.             PAINTSTRUCT ps;
  165.             HDC hdc = BeginPaint(hWnd, &ps);
  166.             // TODO: Add any drawing code that uses hdc here...
  167.             RECT rt;
  168.             GetClientRect(hWnd, &rt);
  169.             DRAW_Waves_and_Ship(hdc, ak, (int)rt.right, (int)rt.bottom);
  170.             EndPaint(hWnd, &ps);
  171.         }
  172.         break;
  173.     case WM_DESTROY:
  174.         PostQuitMessage(0);
  175.         break;
  176.     default:
  177.         return DefWindowProc(hWnd, message, wParam, lParam);
  178.     }
  179.     return 0;
  180. }
  181.  
  182. // Message handler for about box.
  183. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  184. {
  185.     UNREFERENCED_PARAMETER(lParam);
  186.     switch (message)
  187.     {
  188.     case WM_INITDIALOG:
  189.         return (INT_PTR)TRUE;
  190.  
  191.     case WM_COMMAND:
  192.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  193.         {
  194.             EndDialog(hDlg, LOWORD(wParam));
  195.             return (INT_PTR)TRUE;
  196.         }
  197.         break;
  198.     }
  199.     return (INT_PTR)FALSE;
  200. }
  201. VOID DRAW_Waves_and_Ship(HDC hdc, int ak, int xend, int yend)
  202. {
  203.  
  204.     // ak – помощен брояч
  205.     // xend, yend – размер на растера
  206.  
  207.     Graphics graphics(hdc);  // инициализация на графичен режим
  208.  
  209.     int dx = xend / 9;                 // определяне на стъпка по х   
  210.     int dy = yend / 2;                 // определяне на стъпка по y
  211.     Point p[] = {           // вълни при положение 1
  212.            Point(0, dy + 5),   // стартова точка на първия сплайн
  213.            Point(dx, dy + 30),    // първа управляваща точка на първия сплайн
  214.            Point(2 * dx, dy - 30),    // втора управляваща точка на първия сплайн
  215.            Point(3 * dx, dy + 5),  // крайна точка на първия сплайн и
  216.                              // стартова точка на втория сплайн
  217.            Point(4 * dx, dy + 30),   // първа управляваща точка на втория сплайн
  218.            Point(5 * dx, dy - 30),  // втора управляваща точка на втория сплайн
  219.            Point(6 * dx, dy + 5),  // крайна точка на втория сплайн и
  220.                              // стартова точка на третия сплайн
  221.            Point(7 * dx, dy + 30),  // първа управляваща точка на третия сплайн
  222.            Point(8 * dx, dy - 30),  // втора управляваща точка на третия сплайн
  223.            Point(xend,dy + 5)   // крайна точка на третия сплайн
  224.     };
  225.     Point p1[] = {      // вълни при положение 2
  226.            Point(0, dy + 10),
  227.            Point(dx, dy + 20),
  228.            Point(2 * dx, dy - 20),
  229.            Point(3 * dx, dy + 10),
  230.            Point(4 * dx, dy + 20),
  231.            Point(5 * dx, dy - 20),
  232.            Point(6 * dx, dy + 10),
  233.            Point(7 * dx, dy + 20),
  234.            Point(8 * dx, dy - 20),
  235.            Point(xend, dy + 10)
  236.     };
  237.     Point p2[] = {      // вълни при положение 3
  238.            Point(0, dy + 5),
  239.            Point(dx, dy + 10),
  240.            Point(2 * dx, dy - 10),
  241.            Point(3 * dx, dy + 5),
  242.            Point(4 * dx, dy + 10),
  243.            Point(5 * dx, dy - 10),
  244.            Point(6 * dx, dy + 5),
  245.            Point(7 * dx, dy + 10),
  246.            Point(8 * dx, dy - 10),
  247.            Point(xend, dy + 5)
  248.     };
  249.     Point p3[] = {      // вълни при положение 4
  250.            Point(0, dy),
  251.            Point(dx, dy - 30),
  252.            Point(2 * dx, dy + 30),
  253.            Point(3 * dx, dy),
  254.            Point(4 * dx, dy - 30),
  255.            Point(5 * dx, dy + 30),
  256.            Point(6 * dx, dy),
  257.            Point(7 * dx, dy - 30),
  258.            Point(8 * dx, dy + 30),
  259.            Point(xend, dy)
  260.     };
  261.  
  262.     Pen Neavypen(Color(63, 0, 168, 196)); //цветове на вълните - молив
  263.     SolidBrush Neavybr(Color(63, 0, 168, 196)); //цветове на вълните - четка
  264.     GraphicsPath myPath, myPath1;
  265.  
  266.     myPath.StartFigure();
  267.     switch (ak)
  268.     {
  269.     case 0:
  270.     {
  271.         myPath.AddLine(0, yend, 0, dy + 5);
  272.         myPath.AddBeziers(p2, 10);
  273.         myPath.AddLine(xend, dy + 5, xend, yend);
  274.     }
  275.     break;
  276.     case 1:
  277.     {
  278.         myPath.AddLine(0, yend, 0, dy + 10);
  279.         myPath.AddBeziers(p1, 10);
  280.         myPath.AddLine(xend, dy + 10, xend, yend);
  281.     }
  282.     break;
  283.     case 2:
  284.     {
  285.         myPath.AddLine(0, yend, 0, dy + 5);
  286.         myPath.AddBeziers(p2, 10);
  287.         myPath.AddLine(xend, dy + 5, xend, yend);
  288.     }
  289.     break;
  290.     case 3:
  291.     {
  292.         myPath.AddLine(0, yend, 0, dy);
  293.         myPath.AddBeziers(p3, 10);
  294.         myPath.AddLine(xend, dy, xend, yend);
  295.     }
  296.     break;
  297.     case 4:
  298.     {
  299.         myPath.AddLine(0, yend, 0, dy + 10);
  300.         myPath.AddBeziers(p, 10);
  301.         myPath.AddLine(xend, dy + 10, xend, yend);
  302.     }
  303.     break;
  304.     }
  305.  
  306.     myPath.CloseFigure();
  307.  
  308.     myPath1.StartFigure(); // съставна фигура - кораб
  309.  
  310.     myPath1.AddLine(xend / 4, yend / 2 - 30, xend / 4 + xend / 5, yend / 2 - 30);
  311.     myPath1.AddBezier(xend / 4, yend / 2 - 30, xend / 4 + xend / 12, yend / 2 + 60, xend / 4 + xend / 6, yend / 2 + 60, xend / 4 + xend / 5, yend / 2 - 30);
  312.     myPath1.AddLine(xend / 4 + xend / 10, yend / 2 - 30, xend / 4 + xend / 10, yend / 2 - 80);
  313.     myPath1.AddLine(xend / 4 + xend / 10 - 1, yend / 2 - 80, xend / 4 + xend / 10 - 1, yend / 2 - 30);
  314.     myPath1.CloseFigure();
  315.     SolidBrush Shipbr(Color(164, 0, 168, 16)); //оцветяване на кораба
  316.  
  317.  
  318.     Matrix myMatrix; //иницииране на матрица за трансформации
  319.  
  320.     if ((ak == 1) || (ak == 3))
  321.     {
  322.         //задаване на отместване до началото на координатната система
  323.         myMatrix.Translate(-float(xend / 4 + xend / 10), -float(yend / 4));
  324.         myMatrix.Rotate(-8.0f);  //задаване на ротация
  325.         myPath1.Transform(&myMatrix);
  326.         float sx = float(1) + float(ak) / 10;
  327.         myMatrix.Scale(sx, sx); //задаване на мащабиране
  328.         myMatrix.Translate(+float(1.8 * (xend / 4 + xend / 10)), +float(3 * (yend / 5)), MatrixOrderAppend);//задаване на транслация
  329.         myPath1.Transform(&myMatrix); // придвижване на кораба
  330.     }
  331.     if (ak == 2)
  332.     {
  333.  
  334.         myMatrix.Scale(1.125f, 1.125f);
  335.         myMatrix.Translate(-20.0f, -10.0f, MatrixOrderAppend);
  336.         myPath1.Transform(&myMatrix); // придвижване на кораба
  337.     }
  338.  
  339.     if (ak == 4)
  340.     {
  341.         myMatrix.Translate(-float(xend / 4 + xend / 10), -float(yend / 4));
  342.         myMatrix.Rotate(+5.0f);
  343.         myPath1.Transform(&myMatrix);
  344.         myMatrix.Scale(1.3f, 1.3f);
  345.         myMatrix.Translate(+float(2.2 * (xend / 4 + xend / 10)), +float(1.8 * (yend / 4)), MatrixOrderAppend);
  346.         myPath1.Transform(&myMatrix);
  347.     }
  348.  
  349.     graphics.FillPath(&Shipbr, &myPath1);
  350.  
  351.     graphics.FillPath(&Neavybr, &myPath);
  352.  
  353. }
  354.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement