Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <draw>
- #include <string>
- //Simple Calculator
- //October 03, 2013, Gregory Michalik,
- //DS302 - Pawn Language
- new Label1[]{} = ["1", "2", "3", "+", "-", "s"];
- new Label2[]{} = ["4", "5", "6", ".", "*", "^"];
- new Label3[]{} = ["7", "8", "9", "0", "/", "="];
- new buf[6]{1};
- new sx = 0;
- new sy = 1;
- new Fixed: nbuf = FIX(0.0);
- new tbuf{100} = "";
- new com{1} = "";
- main()
- {
- clear_screen();
- draw_menubar("Select", "Clear", "", "Quit");
- draw_calc();
- draw_sel();
- while (!get_keys(BUTTON4))
- {
- if (get_keys(BUTTON1))
- {
- if(sy == 1){buf=Label1;}
- if(sy == 2){buf=Label2;}
- if(sy == 3){buf=Label3;}
- calc(buf[sx]);
- }
- if (get_keys(BUTTON2))
- {
- nbuf = FIX(0.0);
- tbuf = "";
- com = "";
- fill_rectangle(1,181, 398, 29, Color: blue);
- }
- if (get_keys(SCROLL1_LEFT))
- {
- if(sy==1){sy=3;}else{sy--;}
- draw_calc();
- draw_sel();
- }
- if (get_keys(SCROLL1_RIGHT))
- {
- if(sy==3){sy=1;}else{sy++;}
- draw_calc();
- draw_sel();
- }
- if (get_keys(SCROLL2_LEFT))
- {
- if(sx==0){sx=5;}else{sx--;}
- draw_calc();
- draw_sel();
- }
- if (get_keys(SCROLL2_RIGHT))
- {
- if(sx==5){sx=0;}else{sx++;}
- draw_calc();
- draw_sel();
- }
- }
- }
- calc(const command{})
- {
- if (strequal(command,"*")){com="*";nbuf=strfixed(tbuf);tbuf="";}
- if (strequal(command,"/")){com="/";nbuf=strfixed(tbuf);tbuf="";}
- if (strequal(command,"^")){com="^";nbuf=strfixed(tbuf);tbuf="";}
- if (strequal(command,"+")){com="+";nbuf=strfixed(tbuf);tbuf="";}
- if (strequal(command,"-")){com="-";nbuf=strfixed(tbuf);tbuf="";}
- if (strequal(command,"s")){com="s";nbuf=sqrt(strfixed(tbuf));tbuf=strf(nbuf);}
- if (strequal(com,"=")){tbuf="";com="";}
- if (strequal(command,"="))
- {
- if (strequal(com,"+")){nbuf=fadd(nbuf,strfixed(tbuf));}
- if (strequal(com,"*")){nbuf=fmul(nbuf,strfixed(tbuf));}
- if (strequal(com,"-")){nbuf=fsub(nbuf,strfixed(tbuf));}
- if (strequal(com,"/")){nbuf=fdiv(nbuf,strfixed(tbuf));}
- if (strequal(com,"^")){nbuf=pow(nbuf,strval(tbuf));}
- com="=";
- tbuf=strf(nbuf);
- }
- if (strequal(command,"0")){strcat(tbuf, command);}
- if (strequal(command,"1")){strcat(tbuf, command);}
- if (strequal(command,"2")){strcat(tbuf, command);}
- if (strequal(command,"3")){strcat(tbuf, command);}
- if (strequal(command,"4")){strcat(tbuf, command);}
- if (strequal(command,"5")){strcat(tbuf, command);}
- if (strequal(command,"6")){strcat(tbuf, command);}
- if (strequal(command,"7")){strcat(tbuf, command);}
- if (strequal(command,"8")){strcat(tbuf, command);}
- if (strequal(command,"9")){strcat(tbuf, command);}
- if (strequal(command,".")){strcat(tbuf, command);}
- fill_rectangle(1,181, 398, 29, Color: blue);
- draw_text(tbuf, 1, 186, .fg = white, .bg = blue);
- }
- draw_sel()
- {
- //Draw Number Buttons
- new k = 1;
- new j = 0;
- for (new y = 110; y >= 0; y = y - 55)
- {
- for (new x = 0; x <= 110; x = x + 55)
- {
- if((sx == j) & (sy == k))
- {
- draw_rectangle(x, y, 50, 50);
- fill_rectangle(x+1, y+1, 49, 49, Color: blue);
- if(k == 1){buf=Label1;}
- if(k == 2){buf=Label2;}
- if(k == 3){buf=Label3;}
- draw_text(buf[j], x+20, y+15, .fg = white, .bg = blue);
- }
- j++;
- }
- k++;
- j=0;
- }
- //Draw Action Buttons
- k = 1;
- j = 3;
- for (new y = 110; y >= 0; y = y - 55)
- {
- for (new x = 171; x <= 281; x = x + 55)
- {
- if((sx == j) & (sy == k))
- {
- draw_rectangle(x, y, 50, 50);
- fill_rectangle(x+1, y+1, 49, 49, Color: blue);
- if(k == 1){buf=Label1;}
- if(k == 2){buf=Label2;}
- if(k == 3){buf=Label3;}
- draw_text(buf[j], x+20, y+15, .fg = white, .bg = blue);
- }
- j++;
- }
- k++;
- j=3;
- }
- }
- draw_calc()
- {
- draw_rectangle(0, 180, 400, 30);
- fill_rectangle(1,181, 398, 29, Color: blue);
- draw_text(tbuf, 1, 186, .fg = white, .bg = blue);
- // Draw Blue seporator
- fill_rectangle(165, 0, 2, 161, Color: blue);
- // Draw Number Buttons
- new k = 1;
- new j = 0;
- for (new y = 110; y >= 0; y = y - 55)
- {
- for (new x = 0; x <= 110; x = x + 55)
- {
- draw_rectangle(x, y, 50, 50);
- fill_rectangle(x+1, y+1, 49, 49, Color: darkgreen);
- if(k == 1){buf=Label1;}
- if(k == 2){buf=Label2;}
- if(k == 3){buf=Label3;}
- draw_text(buf[j], x+20, y+15, .fg = white, .bg = darkgreen);
- j++;
- }
- k++;
- j=0;
- }
- //Draw Action Buttons
- k = 1;
- j = 3;
- for (new y = 110; y >= 0; y = y - 55)
- {
- for (new x = 171; x <= 281; x = x + 55)
- {
- draw_rectangle(x, y, 50, 50);
- fill_rectangle(x+1, y+1, 49, 49, Color: darkgreen);
- if(k == 1){buf=Label1;}
- if(k == 2){buf=Label2;}
- if(k == 3){buf=Label3;}
- draw_text(buf[j], x+20, y+15, .fg = white, .bg = darkgreen);
- j++;
- }
- k++;
- j=3;
- }
- }
- /* Program info */
- new const program_icon[] = [
- 0b11111111111111111111111111111111,
- 0b11111111111111111111111111111111,
- 0b11100000000000000000000000000111,
- 0b11100000000000000000000000000111,
- 0b11100000000000000000000000000111,
- 0b11111111111111111111111111111111,
- 0b11111111111111111111111111111111,
- 0b11000001000001000001000001000001,
- 0b11000001000001000001000001000001,
- 0b11000001000001000001000001000001,
- 0b11111111111111111111111111111111,
- 0b11000001000001000001000001000001,
- 0b11000001000001000001000001000001,
- 0b11000001000001000001000001000001,
- 0b11111111111111111111111111111111,
- 0b11000001000001000001000001000001,
- 0b11000001000001000001000001000001,
- 0b11000001000001000001000001000001,
- 0b11111111111111111111111111111111,
- 0b11111111111111111111111111111111,
- ];
- new const program_name{} = "Calculator";
- #include <metadata>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement