abubaca

Untitled

Dec 23rd, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <iostream>
  2. #include "windows.h"
  3. #include <vector>
  4. #include <string>
  5. #include <conio.h>
  6. #include <functional>
  7.  
  8. using namespace std;
  9.  
  10. HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  11. #define WIDTH 80
  12. #define HEIGHT 30
  13.  
  14. void print(const char text[], int x, int y)
  15. {
  16.     COORD pos;
  17.     pos.X = x;
  18.     pos.Y = y;
  19.     SetConsoleCursorPosition(hCon, pos);
  20.     cout << text;
  21. }
  22.  
  23. class menu
  24. {
  25.     vector <string> points;
  26.     vector <function<void()>> actions;
  27.     int point = 0;
  28.     void show()
  29.     {
  30.         system("cls");
  31.         int xMiddle = WIDTH / 2;
  32.         int yPart = HEIGHT / (points.size() + 1);
  33.         for (int i = 0; i < points.size(); i++)
  34.         {
  35.             if (i == point)
  36.             {
  37.                 string temp = "<<" + points[i] + ">>";
  38.                 print(temp.c_str(), xMiddle - temp.length() / 2, yPart*(i+1));
  39.             }
  40.             else
  41.                 print(points[i].c_str(), xMiddle - points[i].length() / 2, yPart*(i+1));
  42.         }
  43.     }
  44.     void up()
  45.     {
  46.         point = point == 0 ? points.size() - 1 : point - 1;
  47.     }
  48.     void down()
  49.     {
  50.         point = point == points.size() - 1 ? 0 : point + 1;
  51.     }
  52.     void enter()
  53.     {
  54.         actions[point]();
  55.     }
  56.     public:
  57.         void add(string newP, function<void()> newA)
  58.         {
  59.             points.push_back(newP);
  60.             actions.push_back(newA);
  61.         }
  62.         void get()
  63.         {
  64.             show();
  65.             int button;
  66.             while (true)
  67.             {
  68.                 button = _getch();
  69.                 switch (button)
  70.                 {
  71.                 case 72:
  72.                     up();
  73.                     break;
  74.                 case 80:
  75.                     down();
  76.                     break;
  77.                 case 13:
  78.                     enter();
  79.                     break;
  80.                 case 27:
  81.                     return;
  82.                     break;
  83.                 }
  84.                 show();
  85.             }
  86.         }
  87. };
  88.  
  89. void calck_sin()
  90. {
  91.     system("cls");
  92.     print("sin", WIDTH / 2, HEIGHT / 2);
  93.     cin.get();
  94. }
  95.  
  96. void calck_cos()
  97. {
  98. }
  99.  
  100. void calck_simple()
  101. {
  102. }
  103.  
  104. int main()
  105. {
  106.     string resize = "mode "+ to_string(WIDTH)+ ", "+ to_string(HEIGHT);
  107.     system(resize.c_str());
  108.     menu first;
  109.     first.add("sin", calck_sin);
  110.     first.add("cos", calck_cos);
  111.     first.add("simple function", calck_simple);
  112.     first.get();
  113. }
Advertisement
Add Comment
Please, Sign In to add comment