Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <conio.h>
- #include <stdio.h>
- const int midX = 320;
- const int midY = 240;
- const int buttonBoundY = 400;
- const int param_x = 50;
- const int param_y = 30;
- const int param_width = 160;
- const int param_height = 250;
- const int a_x = 50;
- const int a_y = param_y + param_height + 20;
- const int a_width = 95;
- const int a_height = 30;
- // button size
- const int button_width = 130;
- const int button_height = 30;
- const int paramB_x = 35;
- const int paramB_y = buttonBoundY + 35;
- const int graphic_x = midX - 65;
- const int graphic_y = buttonBoundY + 35;
- const int exit_x = 640 - 35 - 130;
- const int exit_y = buttonBoundY + 35;
- void writeParam() {
- outtextxy(paramB_x + 25, paramB_y + 8, "NEW PARAM");
- }
- void writeGraphic() {
- outtextxy(graphic_x + 40, graphic_y + 8, "GRAFIC");
- }
- void writeExit() {
- outtextxy(exit_x + 50, exit_y + 8, "EXIT");
- }
- void GetGraphic() {
- line(midX, 0, midX, buttonBoundY);
- line(0, buttonBoundY, 639, buttonBoundY);
- // XY param
- rectangle(param_x, param_y, param_x + param_width, param_y + param_height);
- line(param_x + param_width / 2, param_y, param_x + param_width / 2, param_y + param_height);
- line(param_x, param_y + 45, param_x + param_width, param_y + 45);
- outtextxy(param_x + 37, param_y + 10, "X");
- outtextxy(param_x + 37 + 80, param_y + 10, "Y");
- // a =
- rectangle(a_x, a_y, a_x + a_width, a_y + a_height);
- outtextxy(a_x + 10, a_y + 5, "a=");
- // b =
- int b_x = 50;
- int b_y = a_y + a_height + 15;
- int b_width = 95;
- int b_height = 30;
- rectangle(b_x, b_y, b_x + b_width, b_y + b_height);
- outtextxy(b_x + 10, b_y + 5, "b=");
- // XY coordinates
- line(midX + 40, 200, 600, 200);
- line(midX + 160, 40, midX + 160, 360);
- outtextxy(midX + 147, 203, "0");
- line(midX + 155, 40, midX + 165, 40);
- line(midX + 160, 30, midX + 155, 40);
- line(midX + 160, 30, midX + 165, 40);
- floodfill(midX + 160, 39, WHITE);
- outtextxy(midX + 140, 40, "Y");
- line(600, 195, 600, 205);
- line(610, 200, 600, 195);
- line(610, 200, 600, 205);
- floodfill(601, 200, WHITE);
- outtextxy(590, 210, "X");
- // ParamButton
- rectangle(paramB_x, paramB_y, paramB_x + button_width, paramB_y + button_height);
- writeParam();
- // GraphicButton
- rectangle(graphic_x, graphic_y, graphic_x + button_width, graphic_y + button_height);
- writeGraphic();
- // EXIT_Button
- rectangle(exit_x, exit_y, exit_x + button_width, exit_y + button_height);
- writeExit();
- }
- void paintButton(int num) {
- int begin_x, begin_y, end_x, end_y;
- if (num == 1) {
- begin_x = paramB_x, begin_y = paramB_y;
- end_x = paramB_x + button_width, end_y = paramB_y + button_height;
- }
- if (num == 2) {
- begin_x = graphic_x, begin_y = graphic_y;
- end_x = graphic_x + button_width, end_y = graphic_y + button_height;
- }
- if (num == 3) {
- begin_x = exit_x, begin_y = exit_y;
- end_x = exit_x + button_width, end_y = exit_y + button_height;
- }
- setfillstyle(1, GREEN);
- bar(begin_x + 1, begin_y + 1, end_x, end_y);
- setbkcolor(GREEN);
- if (num == 1)
- writeParam();
- if (num == 2)
- writeGraphic();
- if (num == 3)
- writeExit();
- }
- void clearButton(int num) {
- int begin_x, begin_y, end_x, end_y;
- if (num == 1) {
- begin_x = paramB_x, begin_y = paramB_y;
- end_x = paramB_x + button_width, end_y = paramB_y + button_height;
- }
- if (num == 2) {
- begin_x = graphic_x, begin_y = graphic_y;
- end_x = graphic_x + button_width, end_y = graphic_y + button_height;
- }
- if (num == 3) {
- begin_x = exit_x, begin_y = exit_y;
- end_x = exit_x + button_width, end_y = exit_y + button_height;
- }
- setfillstyle(1, BLACK);
- bar(begin_x + 1, begin_y + 1, end_x, end_y);
- setbkcolor(BLACK);
- if (num == 1)
- writeParam();
- if (num == 2)
- writeGraphic();
- if (num == 3)
- writeExit();
- }
- int main(void)
- {
- int GrDr, GrMod, rez ;
- GrDr=DETECT ;
- initgraph(&GrDr,&GrMod," ");
- rez=graphresult() ;
- if(rez != grOk)
- {
- printf("\n Error graph modeи") ;
- return(1) ;
- }
- GetGraphic();
- int cur_button = 1;
- paintButton(cur_button);
- char ch;
- while (true) {
- ch = getch();
- clearButton(cur_button);
- if (ch == 'n') cur_button = 1;
- if (ch == 'g') cur_button = 2;
- if (ch == 'e') cur_button = 3;
- paintButton(cur_button);
- }
- getch() ;
- closegraph() ;
- return(0) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement