Subversion Repositories Kolibri OS

Rev

Rev 4875 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.     VERSION equ "0.1Å"
  2.  
  3.     use32
  4.     org     0
  5.     db      'MENUET01'
  6.     dd      1, main, dataend, memory, stacktop, 0, 0
  7.  
  8.     include "../../proc32.inc"
  9.     include "../../macros.inc"
  10.     include "../../dll.inc"
  11.     include "../../develop/libraries/box_lib/trunk/box_lib.mac"
  12.     include "parser.inc"
  13.  
  14.  ;===============================
  15.  
  16.     sz_head db "Calc+ [v", VERSION, "]", 0
  17.     buttons db "1234567890.%-+*/()"
  18.     edb1    edit_box 184, 8, 12, 0, 0, 0, 0, 0, 500, \
  19.                      exp, group, ed_always_focus + ed_focus, 0, 0
  20.  
  21.  imports:
  22.     library gui, "box_lib.obj"
  23.     import  gui, editbox.draw,  "edit_box",     \
  24.                  editbox.key,   "edit_box_key", \
  25.                  editbox.mouse, "edit_box_mouse"
  26.  
  27.  ;===============================
  28.  
  29.  main:
  30.     mov     [ans.buffer], word "0"
  31.     mov     [ans.size], 15
  32.  
  33.     mcall   40, 100111b
  34.     mcall   48, 3, scn, 192
  35.  
  36.     m2m     [edb1.color],              [scn.gui_face]
  37.     m2m     [edb1.shift_color],        [scn.gui_select]
  38.     m2m     [edb1.focus_border_color], [scn.gui_face]
  39.     m2m     [edb1.text_color],         [scn.gui_fctext]
  40.  
  41.     mcall   68, 11
  42.     stdcall dll.Load, imports
  43.  
  44.  ;----------------------
  45.  
  46.  update:
  47.     mcall   23, 50
  48.  
  49.     cmp     eax, EV_REDRAW
  50.     je      ev_redraw
  51.     cmp     eax, EV_KEY
  52.     je      ev_key
  53.     cmp     eax, EV_BUTTON
  54.     je      ev_button
  55.     cmp     eax, EV_MOUSE
  56.     je      ev_mouse
  57.  
  58.     dec     [timer]
  59.     cmp     [timer], 0
  60.     je      calc
  61.  
  62.     jmp     update
  63.  
  64.  ;----------------------
  65.  
  66.  ev_redraw:
  67.     mov     edx, [scn.win_body]
  68.     or      edx, 0x34 shl 24
  69.     mcall    0, <100, 236>, <100, 164>, , , sz_head
  70.  
  71.     mcall   13, <  4, 220>, <  8,  23>, [scn.gui_frame]
  72.     mov     edx, [scn.gui_face]
  73.     cmp     [error_n], 0
  74.     je      @f
  75.     mov     edx, 0xFFAAAA
  76.   @@:
  77.     mcall   13, <  5, 218>, <  9, 21>
  78.     mcall     , <  5, 218>, <  9,  1>, [scn.3d_face]
  79.     mcall     , <  5,   1>, < 10, 20>
  80.     mcall     , <  5, 218>, < 31,  1>, [scn.3d_light]
  81.  
  82.     mov     ebx, 224
  83.     sub     ebx, [ans.size]
  84.     shl     ebx, 16
  85.     inc     ebx
  86.     mcall     ,           , < 9, 21>, [scn.gui_frame]
  87.     add     ebx, [ans.size]
  88.     add     ebx, 1 shl 16
  89.     sub     ebx, 3
  90.     mcall     ,           ,         , [scn.3d_light]
  91.     add     ebx, 1 shl 16
  92.     add     ecx, 1 shl 16
  93.     dec     ebx
  94.     dec     ecx
  95.     mcall     ,           ,         , [scn.win_face]
  96.     shr     ecx, 16
  97.     mov     bx, cx
  98.     add     ebx, 3 shl 16 + 6
  99.     mov     ecx, [scn.win_text]
  100.     or      ecx, 1b shl 31
  101.     mcall   4, , , ans.buffer
  102.  
  103.     mcall    1,   4,  8, [scn.win_body]
  104.     mcall     , 223
  105.     mcall     ,    , 30, [scn.3d_light]
  106.     mcall     ,   4
  107.  
  108.     mov     ebx, 214
  109.     sub     ebx, [ans.size]
  110.     cmp     ebx, 24
  111.     jg      @f
  112.     mov     ebx, 24
  113.   @@:
  114.     mov     [edb1.width], ebx
  115.     m2m     [edb1.color],              [scn.gui_face]
  116.     m2m     [edb1.focus_border_color], [scn.gui_face]
  117.     cmp     [error_n],  0
  118.     je      @f
  119.     mov     [edb1.color],              0xFFAAAA
  120.     mov     [edb1.focus_border_color], 0xFFAAAA
  121.   @@:
  122.     invoke  editbox.draw, edb1
  123.  
  124.     mov     [but_id], 0x4000000A
  125.     stdcall draw_button,   4, 38,  42, buttons + 00, 15
  126.     stdcall draw_button,  46, 38,  42, buttons + 01, 15
  127.     stdcall draw_button,  88, 38,  42, buttons + 02, 15
  128.     stdcall draw_button,   4, 38,  66, buttons + 03, 15
  129.     stdcall draw_button,  46, 38,  66, buttons + 04, 15
  130.     stdcall draw_button,  88, 38,  66, buttons + 05, 15
  131.     stdcall draw_button,   4, 38,  90, buttons + 06, 15
  132.     stdcall draw_button,  46, 38,  90, buttons + 07, 15
  133.     stdcall draw_button,  88, 38,  90, buttons + 08, 15
  134.     stdcall draw_button,   4, 80, 114, buttons + 09, 35
  135.     stdcall draw_button,  88, 38, 114, buttons + 10, 15
  136.  
  137.     stdcall draw_button, 144, 38,  42, buttons + 11, 15
  138.     stdcall draw_button, 186, 38,  42, buttons + 12, 15
  139.     stdcall draw_button, 144, 38,  66, buttons + 13, 15
  140.     stdcall draw_button, 186, 38,  66, buttons + 14, 15
  141.     stdcall draw_button, 144, 38,  90, buttons + 15, 15
  142.     stdcall draw_button, 186, 38,  90, buttons + 16, 15
  143.     stdcall draw_button, 144, 38, 114, buttons + 17, 15
  144.     stdcall draw_button, 186, 38, 114, buttons + 18, 15
  145.  
  146.     jmp     update
  147.  
  148.  ;----------------------
  149.  
  150.  ev_key:
  151.     mov     [timer], 1
  152.  
  153.     mcall   2
  154.     cmp     ah, 27
  155.     je      exit
  156.     invoke  editbox.key, edb1
  157.     jmp     update
  158.  
  159.  ;----------------------
  160.  
  161.  ev_button:
  162.     mov     [timer], 1
  163.  
  164.     mcall   17
  165.  
  166.     cmp     ah, 1
  167.     je      exit
  168.  
  169.     cmp     ah, 22
  170.     jne     .not_del
  171.  
  172.     cmp     [edb1.pos], 0
  173.     je      update
  174.     mov     eax, exp
  175.     add     eax, [edb1.pos]
  176.     dec     eax
  177.     mov     ebx, exp
  178.     add     ebx, [edb1.size]
  179.     inc     ebx
  180.   @@:
  181.     cmp     eax, ebx
  182.     je      @f
  183.     mov     cl, [eax + 1]
  184.     mov     [eax], cl
  185.     inc     eax
  186.     jmp     @b
  187.   @@:
  188.     dec     [edb1.pos]
  189.     dec     [edb1.size]
  190.     m2m     [edb1.shift], [edb1.pos]
  191.     jmp     ev_redraw
  192.  
  193.  .not_del:
  194.  
  195.     cmp     ah, 10
  196.     jl      update
  197.     cmp     ah, 50
  198.     jg      update
  199.  
  200.     movzx   eax, ah
  201.     add     eax, buttons
  202.     sub     eax, 10
  203.     mov     al, [eax]
  204.  
  205.     mov     ebx, exp
  206.     add     ebx, [edb1.size]
  207.     mov     ecx, exp
  208.     add     ecx, [edb1.pos]
  209.   @@:
  210.     cmp     ebx, ecx
  211.     je      @f
  212.     mov     dl, [ebx - 1]
  213.     mov     [ebx], dl
  214.     dec     ebx
  215.     jmp     @b
  216.   @@:
  217.  
  218.     mov     [ebx], al
  219.     inc     [edb1.size]
  220.     inc     [edb1.pos]
  221.  
  222.     jmp     ev_redraw
  223.  
  224.  ;----------------------
  225.  
  226.  ev_mouse:
  227.     mcall   2
  228.  
  229.     invoke  editbox.mouse, edb1
  230.     jmp     update
  231.  
  232.  ;----------------------
  233.  
  234.  exit:
  235.     mcall   -1
  236.  
  237.  ;----------------------
  238.  
  239.  calc:
  240.     stdcall parse
  241.     cmp     [error_n], 0
  242.     jne     .error
  243.  
  244.     stdcall convert_to_str, eax, ans.buffer
  245.     imul    eax, 6
  246.     add     eax, 9
  247.     mov     [ans.size], eax
  248.     jmp     ev_redraw
  249.  
  250.  .error:
  251.     cmp     [error_n], 1
  252.     je      .err_1
  253.     jmp     ev_redraw
  254.  .err_1:
  255.     mov     [ans.buffer +  0], dword "Div."
  256.     mov     [ans.buffer +  4], dword " by "
  257.     mov     [ans.buffer +  8], dword "zero"
  258.     mov     [ans.buffer + 12], byte 0
  259.     mov     [ans.size], 81
  260.     jmp     ev_redraw
  261.  
  262.  ;----------------------
  263.  
  264.  proc draw_button, x, w, y, txt, txtx
  265.     mcall   13, <[x], [w]>, <[y], 20>, [scn.gui_frame]
  266.  
  267.     add     ebx, 1 shl 16
  268.     add     ecx, 1 shl 16
  269.     sub     ebx, 2
  270.     sub     ecx, 2
  271.     mcall   , , , [scn.3d_light]
  272.  
  273.     add     ebx, 1 shl 16
  274.     add     ecx, 1 shl 16
  275.     dec     ebx
  276.     dec     ecx
  277.     mcall   , , , [scn.3d_dark]
  278.  
  279.     dec     ebx
  280.     dec     ecx
  281.     mcall   , , , [scn.win_face]
  282.  
  283.     mcall   1, [x], [y], [scn.win_body]
  284.  
  285.     add     ebx, [w]
  286.     dec     ebx
  287.     mcall
  288.  
  289.     add     ecx, 20
  290.     dec     ecx
  291.     mcall
  292.  
  293.     sub     ebx, [w]
  294.     inc     ebx
  295.     mcall
  296.  
  297.     mov     ebx, [x]
  298.     inc     ebx
  299.     shl     ebx, 16
  300.     add     ebx, [w]
  301.     sub     ebx, 3
  302.     mov     ecx, [y]
  303.     inc     ecx
  304.     shl     ecx, 16
  305.     add     ecx, 20
  306.     sub     ecx, 3
  307.     mov     edx, [but_id]
  308.     mcall   8
  309.     inc     dword[but_id]
  310.  
  311.     mov     ebx, [x]
  312.     add     ebx, [txtx]
  313.     shl     ebx, 16
  314.     add     ebx, [y]
  315.     add     ebx, 7
  316.     mcall   4, , [scn.win_text], [txt], 1
  317.  
  318.     ret
  319.  endp
  320.  
  321.  ;----------------------
  322.  
  323.  dataend:
  324.  
  325.  ;===============================
  326.  
  327.             rb 2048
  328.  stacktop:
  329.  
  330.  exp        rb 512
  331.  exp_pos    rd 1
  332.  exp_lvl    rd 1
  333.  group      rd 1
  334.  
  335.  ans.buffer:rb 512
  336.  ans.size   rd 1
  337.  error_n    rd 1
  338.  
  339.  scn        sys_colors_new
  340.  timer      rd 1
  341.  but_id     rd 1
  342.  
  343.  memory:
  344.