Advertisement
Mirbek

Lab3

Mar 15th, 2022
1,343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.66 KB | None | 0 0
  1. #include <graphics.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4.  
  5. const int midX = 320;
  6. const int midY = 240;
  7. const int buttonBoundY = 400;
  8.  
  9. const int param_x = 50;
  10. const int param_y = 30;
  11. const int param_width = 160;
  12. const int param_height = 250;
  13.  
  14. const int a_x = 50;
  15. const int a_y = param_y + param_height + 20;
  16. const int a_width = 95;
  17. const int a_height = 30;
  18.  
  19.  
  20. // button size
  21. const int button_width = 130;
  22. const int button_height = 30;
  23.  
  24. const int paramB_x = 35;
  25. const int paramB_y = buttonBoundY + 35;
  26.  
  27. const int graphic_x = midX - 65;
  28. const int graphic_y = buttonBoundY + 35;
  29.  
  30. const int exit_x = 640 - 35 - 130;
  31. const int exit_y = buttonBoundY + 35;
  32.  
  33. void writeParam() {
  34.     outtextxy(paramB_x + 25, paramB_y + 8, "NEW PARAM");
  35. }
  36.  
  37. void writeGraphic() {
  38.     outtextxy(graphic_x + 40, graphic_y + 8, "GRAFIC");
  39. }
  40.  
  41. void writeExit() {
  42.     outtextxy(exit_x + 50, exit_y + 8, "EXIT");
  43. }
  44.  
  45. void GetGraphic() {
  46.  
  47.     line(midX, 0, midX, buttonBoundY);
  48.     line(0, buttonBoundY, 639, buttonBoundY);
  49.  
  50.     // XY param
  51.     rectangle(param_x, param_y, param_x + param_width, param_y + param_height);
  52.     line(param_x + param_width / 2, param_y, param_x + param_width / 2, param_y + param_height);
  53.     line(param_x, param_y + 45, param_x + param_width, param_y + 45);
  54.     outtextxy(param_x + 37, param_y + 10, "X");
  55.     outtextxy(param_x + 37 + 80, param_y + 10, "Y");
  56.  
  57.     // a =
  58.     rectangle(a_x, a_y, a_x + a_width, a_y + a_height);
  59.     outtextxy(a_x + 10, a_y + 5, "a=");
  60.  
  61.     // b =
  62.     int b_x = 50;
  63.     int b_y = a_y + a_height + 15;
  64.     int b_width = 95;
  65.     int b_height = 30;
  66.     rectangle(b_x, b_y, b_x + b_width, b_y + b_height);
  67.     outtextxy(b_x + 10, b_y + 5, "b=");
  68.  
  69.     // XY coordinates
  70.     line(midX + 40, 200, 600, 200);
  71.     line(midX + 160, 40, midX + 160, 360);
  72.     outtextxy(midX + 147, 203, "0");
  73.  
  74.     line(midX + 155, 40, midX + 165, 40);
  75.     line(midX + 160, 30, midX + 155, 40);
  76.     line(midX + 160, 30, midX + 165, 40);
  77.     floodfill(midX + 160, 39, WHITE);
  78.     outtextxy(midX + 140, 40, "Y");
  79.  
  80.     line(600, 195, 600, 205);
  81.     line(610, 200, 600, 195);
  82.     line(610, 200, 600, 205);
  83.     floodfill(601, 200, WHITE);
  84.     outtextxy(590, 210, "X");
  85.  
  86.     // ParamButton
  87.     rectangle(paramB_x, paramB_y, paramB_x + button_width, paramB_y + button_height);
  88.     writeParam();
  89.  
  90.     // GraphicButton
  91.     rectangle(graphic_x, graphic_y, graphic_x + button_width, graphic_y + button_height);
  92.     writeGraphic();
  93.  
  94.     // EXIT_Button
  95.     rectangle(exit_x, exit_y, exit_x + button_width, exit_y + button_height);
  96.     writeExit();
  97. }
  98.  
  99. void paintButton(int num) {
  100.     int begin_x, begin_y, end_x, end_y;
  101.     if (num == 1) {
  102.         begin_x = paramB_x, begin_y = paramB_y;
  103.         end_x = paramB_x + button_width, end_y = paramB_y + button_height;
  104.     }
  105.     if (num == 2) {
  106.         begin_x = graphic_x, begin_y = graphic_y;
  107.         end_x = graphic_x + button_width, end_y = graphic_y + button_height;
  108.     }
  109.     if (num == 3) {
  110.         begin_x = exit_x, begin_y = exit_y;
  111.         end_x = exit_x + button_width, end_y = exit_y + button_height;
  112.     }
  113.     setfillstyle(1, GREEN);
  114.     bar(begin_x + 1, begin_y + 1, end_x, end_y);
  115.     setbkcolor(GREEN);
  116.     if (num == 1)
  117.         writeParam();
  118.     if (num == 2)
  119.         writeGraphic();
  120.     if (num == 3)
  121.         writeExit();
  122. }
  123.  
  124. void clearButton(int num) {
  125.     int begin_x, begin_y, end_x, end_y;
  126.     if (num == 1) {
  127.         begin_x = paramB_x, begin_y = paramB_y;
  128.         end_x = paramB_x + button_width, end_y = paramB_y + button_height;
  129.     }
  130.     if (num == 2) {
  131.         begin_x = graphic_x, begin_y = graphic_y;
  132.         end_x = graphic_x + button_width, end_y = graphic_y + button_height;
  133.     }
  134.     if (num == 3) {
  135.         begin_x = exit_x, begin_y = exit_y;
  136.         end_x = exit_x + button_width, end_y = exit_y + button_height;
  137.     }
  138.     setfillstyle(1, BLACK);
  139.     bar(begin_x + 1, begin_y + 1, end_x, end_y);
  140.     setbkcolor(BLACK);
  141.     if (num == 1)
  142.         writeParam();
  143.     if (num == 2)
  144.         writeGraphic();
  145.     if (num == 3)
  146.         writeExit();
  147. }
  148.  
  149. int main(void)
  150. {
  151.     int GrDr, GrMod, rez ;
  152.     GrDr=DETECT ;
  153.  
  154.     initgraph(&GrDr,&GrMod," ");
  155.     rez=graphresult() ;
  156.     if(rez != grOk)
  157.     {
  158.         printf("\n Error graph modeи") ;
  159.         return(1) ;
  160.     }
  161.  
  162.     GetGraphic();
  163.  
  164.     int cur_button = 1;
  165.  
  166.     paintButton(cur_button);
  167.  
  168.     char ch;
  169.     while (true) {
  170.         ch = getch();
  171.         clearButton(cur_button);
  172.         if (ch == 'n') cur_button = 1;
  173.         if (ch == 'g') cur_button = 2;
  174.         if (ch == 'e') cur_button = 3;
  175.         paintButton(cur_button);
  176.     }
  177.  
  178.     getch() ;
  179.     closegraph() ;
  180.     return(0) ;
  181. }
  182.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement