Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "windows.h"
- #include <vector>
- #include <string>
- #include <conio.h>
- #include <functional>
- using namespace std;
- HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
- #define WIDTH 80
- #define HEIGHT 30
- void print(const char text[], int x, int y)
- {
- COORD pos;
- pos.X = x;
- pos.Y = y;
- SetConsoleCursorPosition(hCon, pos);
- cout << text;
- }
- class menu
- {
- vector <string> points;
- vector <function<void()>> actions;
- int point = 0;
- void show()
- {
- system("cls");
- int xMiddle = WIDTH / 2;
- int yPart = HEIGHT / (points.size() + 1);
- for (int i = 0; i < points.size(); i++)
- {
- if (i == point)
- {
- string temp = "<<" + points[i] + ">>";
- print(temp.c_str(), xMiddle - temp.length() / 2, yPart*(i+1));
- }
- else
- print(points[i].c_str(), xMiddle - points[i].length() / 2, yPart*(i+1));
- }
- }
- void up()
- {
- point = point == 0 ? points.size() - 1 : point - 1;
- }
- void down()
- {
- point = point == points.size() - 1 ? 0 : point + 1;
- }
- void enter()
- {
- actions[point]();
- }
- public:
- void add(string newP, function<void()> newA)
- {
- points.push_back(newP);
- actions.push_back(newA);
- }
- void get()
- {
- show();
- int button;
- while (true)
- {
- button = _getch();
- switch (button)
- {
- case 72:
- up();
- break;
- case 80:
- down();
- break;
- case 13:
- enter();
- break;
- case 27:
- return;
- break;
- }
- show();
- }
- }
- };
- void calck_sin()
- {
- system("cls");
- print("sin", WIDTH / 2, HEIGHT / 2);
- cin.get();
- }
- void calck_cos()
- {
- }
- void calck_simple()
- {
- }
- int main()
- {
- string resize = "mode "+ to_string(WIDTH)+ ", "+ to_string(HEIGHT);
- system(resize.c_str());
- menu first;
- first.add("sin", calck_sin);
- first.add("cos", calck_cos);
- first.add("simple function", calck_simple);
- first.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment