Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2013
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.66 KB | None | 0 0
  1. #include <draw>
  2. #include <string>
  3.  
  4. //Simple Calculator
  5. //October 03, 2013, Gregory Michalik,
  6. //DS302 - Pawn Language
  7.  
  8. new Label1[]{} = ["1", "2", "3", "+", "-", "s"];
  9. new Label2[]{} = ["4", "5", "6", ".", "*", "^"];
  10. new Label3[]{} = ["7", "8", "9", "0", "/", "="];
  11. new buf[6]{1};
  12. new sx = 0;
  13. new sy = 1;
  14. new Fixed: nbuf = FIX(0.0);
  15. new tbuf{100} = "";
  16. new com{1} = "";
  17.  
  18. main()
  19. {
  20.     clear_screen();
  21.     draw_menubar("Select", "Clear", "", "Quit");
  22.     draw_calc();
  23.     draw_sel();
  24.    
  25.     while (!get_keys(BUTTON4))
  26.     {
  27.         if (get_keys(BUTTON1))
  28.         {
  29.             if(sy == 1){buf=Label1;}
  30.             if(sy == 2){buf=Label2;}
  31.             if(sy == 3){buf=Label3;}
  32.             calc(buf[sx]);
  33.         }
  34.         if (get_keys(BUTTON2))
  35.         {
  36.             nbuf = FIX(0.0);
  37.             tbuf = "";
  38.             com = "";
  39.             fill_rectangle(1,181, 398, 29, Color: blue);
  40.         }
  41.         if (get_keys(SCROLL1_LEFT))
  42.         {
  43.             if(sy==1){sy=3;}else{sy--;}
  44.             draw_calc();
  45.             draw_sel();
  46.         }
  47.         if (get_keys(SCROLL1_RIGHT))
  48.         {
  49.             if(sy==3){sy=1;}else{sy++;}
  50.             draw_calc();
  51.             draw_sel();
  52.         }
  53.         if (get_keys(SCROLL2_LEFT))
  54.         {
  55.             if(sx==0){sx=5;}else{sx--;}
  56.             draw_calc();
  57.             draw_sel();
  58.         }
  59.         if (get_keys(SCROLL2_RIGHT))
  60.         {
  61.             if(sx==5){sx=0;}else{sx++;}
  62.             draw_calc();
  63.             draw_sel();
  64.         }
  65.     }
  66.    
  67. }
  68.  
  69. calc(const command{})
  70. {
  71.     if (strequal(command,"*")){com="*";nbuf=strfixed(tbuf);tbuf="";}
  72.     if (strequal(command,"/")){com="/";nbuf=strfixed(tbuf);tbuf="";}
  73.     if (strequal(command,"^")){com="^";nbuf=strfixed(tbuf);tbuf="";}
  74.     if (strequal(command,"+")){com="+";nbuf=strfixed(tbuf);tbuf="";}
  75.     if (strequal(command,"-")){com="-";nbuf=strfixed(tbuf);tbuf="";}
  76.     if (strequal(command,"s")){com="s";nbuf=sqrt(strfixed(tbuf));tbuf=strf(nbuf);}
  77.    
  78.     if (strequal(com,"=")){tbuf="";com="";}
  79.    
  80.     if (strequal(command,"="))
  81.     {
  82.         if (strequal(com,"+")){nbuf=fadd(nbuf,strfixed(tbuf));}
  83.         if (strequal(com,"*")){nbuf=fmul(nbuf,strfixed(tbuf));}
  84.         if (strequal(com,"-")){nbuf=fsub(nbuf,strfixed(tbuf));}
  85.         if (strequal(com,"/")){nbuf=fdiv(nbuf,strfixed(tbuf));}
  86.         if (strequal(com,"^")){nbuf=pow(nbuf,strval(tbuf));}
  87.         com="=";
  88.         tbuf=strf(nbuf);
  89.     }
  90.    
  91.     if (strequal(command,"0")){strcat(tbuf, command);}
  92.     if (strequal(command,"1")){strcat(tbuf, command);}
  93.     if (strequal(command,"2")){strcat(tbuf, command);}
  94.     if (strequal(command,"3")){strcat(tbuf, command);}
  95.     if (strequal(command,"4")){strcat(tbuf, command);}
  96.     if (strequal(command,"5")){strcat(tbuf, command);}
  97.     if (strequal(command,"6")){strcat(tbuf, command);}
  98.     if (strequal(command,"7")){strcat(tbuf, command);}
  99.     if (strequal(command,"8")){strcat(tbuf, command);}
  100.     if (strequal(command,"9")){strcat(tbuf, command);}
  101.     if (strequal(command,".")){strcat(tbuf, command);}
  102.  
  103.     fill_rectangle(1,181, 398, 29, Color: blue);
  104.     draw_text(tbuf, 1, 186, .fg = white, .bg = blue);
  105. }
  106.  
  107. draw_sel()
  108. {
  109.     //Draw Number Buttons
  110.     new k = 1;
  111.     new j = 0;
  112.     for (new y = 110; y >= 0; y = y - 55)
  113.         {
  114.             for (new x = 0; x <= 110; x = x + 55)
  115.             {
  116.                 if((sx == j) & (sy == k))
  117.                 {
  118.                     draw_rectangle(x, y, 50, 50);
  119.                     fill_rectangle(x+1, y+1, 49, 49, Color: blue);
  120.                     if(k == 1){buf=Label1;}
  121.                     if(k == 2){buf=Label2;}
  122.                     if(k == 3){buf=Label3;}
  123.                     draw_text(buf[j], x+20, y+15, .fg = white, .bg = blue);
  124.                 }    
  125.                 j++;
  126.             }
  127.             k++;
  128.             j=0;
  129.         }
  130.     //Draw Action Buttons
  131.     k = 1;
  132.     j = 3;
  133.     for (new y = 110; y >= 0; y = y - 55)
  134.     {
  135.         for (new x = 171; x <= 281; x = x + 55)
  136.         {
  137.             if((sx == j) & (sy == k))
  138.             {
  139.                 draw_rectangle(x, y, 50, 50);
  140.                 fill_rectangle(x+1, y+1, 49, 49, Color: blue);
  141.                 if(k == 1){buf=Label1;}
  142.                 if(k == 2){buf=Label2;}
  143.                 if(k == 3){buf=Label3;}
  144.                 draw_text(buf[j], x+20, y+15, .fg = white, .bg = blue);
  145.             }
  146.             j++;
  147.         }
  148.         k++;
  149.         j=3;
  150.     }
  151. }
  152.  
  153. draw_calc()
  154. {
  155.     draw_rectangle(0, 180, 400, 30);
  156.     fill_rectangle(1,181, 398, 29, Color: blue);
  157.     draw_text(tbuf, 1, 186, .fg = white, .bg = blue);
  158.    
  159.     // Draw Blue seporator
  160.     fill_rectangle(165, 0, 2, 161, Color: blue);
  161.     // Draw Number Buttons
  162.     new k = 1;
  163.     new j = 0;
  164.     for (new y = 110; y >= 0; y = y - 55)
  165.         {
  166.             for (new x = 0; x <= 110; x = x + 55)
  167.             {
  168.                 draw_rectangle(x, y, 50, 50);
  169.                 fill_rectangle(x+1, y+1, 49, 49, Color: darkgreen);
  170.                 if(k == 1){buf=Label1;}
  171.                 if(k == 2){buf=Label2;}
  172.                 if(k == 3){buf=Label3;}
  173.                
  174.                 draw_text(buf[j], x+20, y+15, .fg = white, .bg = darkgreen);
  175.                 j++;
  176.             }
  177.             k++;
  178.             j=0;
  179.         }
  180.     //Draw Action Buttons
  181.     k = 1;
  182.     j = 3;
  183.     for (new y = 110; y >= 0; y = y - 55)
  184.     {
  185.         for (new x = 171; x <= 281; x = x + 55)
  186.         {
  187.             draw_rectangle(x, y, 50, 50);
  188.             fill_rectangle(x+1, y+1, 49, 49, Color: darkgreen);
  189.             if(k == 1){buf=Label1;}
  190.             if(k == 2){buf=Label2;}
  191.             if(k == 3){buf=Label3;}
  192.             draw_text(buf[j], x+20, y+15, .fg = white, .bg = darkgreen);
  193.             j++;
  194.         }
  195.         k++;
  196.         j=3;
  197.     }
  198. }
  199.  
  200. /* Program info */
  201. new const program_icon[] = [
  202.     0b11111111111111111111111111111111,
  203.     0b11111111111111111111111111111111,
  204.     0b11100000000000000000000000000111,
  205.     0b11100000000000000000000000000111,
  206.     0b11100000000000000000000000000111,
  207.     0b11111111111111111111111111111111,
  208.     0b11111111111111111111111111111111,
  209.     0b11000001000001000001000001000001,
  210.     0b11000001000001000001000001000001,
  211.     0b11000001000001000001000001000001,
  212.     0b11111111111111111111111111111111,
  213.     0b11000001000001000001000001000001,
  214.     0b11000001000001000001000001000001,
  215.     0b11000001000001000001000001000001,
  216.     0b11111111111111111111111111111111,
  217.     0b11000001000001000001000001000001,
  218.     0b11000001000001000001000001000001,
  219.     0b11000001000001000001000001000001,
  220.     0b11111111111111111111111111111111,
  221.     0b11111111111111111111111111111111,
  222. ];
  223.  
  224. new const program_name{} = "Calculator";
  225. #include <metadata>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement