Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;
  3. ; This is example of using GUI component EditBox from libGUI.
  4. ;
  5. ;
  6.  
  7. include 'macros.inc'
  8. use32
  9.         db      'MENUET01'
  10.         dd      1
  11.         dd      start
  12.         dd      i_end
  13.         dd      1800
  14.         dd      1800
  15.         dd      0
  16.         dd      path
  17.  
  18. start:
  19.         ;init hepe of memory
  20.         mcall   68,11
  21.  
  22.         ;set current dir as ./
  23.         call GetPath
  24.  
  25.         ;load dll
  26.         mcall   68,19,path
  27.  
  28.         test    eax,eax
  29.         jnz    libGUI_loaded
  30.  
  31.         mcall 68,19,sys_libGUI_path
  32.  
  33.            test eax,eax
  34.            jnz libGUI_loaded
  35.  
  36.              mcall -1
  37.  
  38.         libGUI_loaded:
  39.  
  40.         mov [myexport],eax
  41.  
  42.         ;load dll functions
  43.  
  44.         push fnDestroyControl
  45.         push [myexport]
  46.         call _ksys_cofflib_getproc
  47.         mov [destroy_control],eax
  48.  
  49.         push fnSendMessage
  50.         push [myexport]
  51.         call _ksys_cofflib_getproc
  52.         mov [send_message],eax
  53.  
  54.         push fnCraeteButton
  55.         push [myexport]
  56.         call _ksys_cofflib_getproc
  57.         mov [craete_button],eax
  58.  
  59.         push fnCraeteEditbox
  60.         push [myexport]
  61.         call _ksys_cofflib_getproc
  62.         mov [craete_edit_box],eax
  63.  
  64.         ;set events mask
  65.         mcall   40,1100111b
  66.  
  67.         ;get standart colors table
  68.         mcall   48,3,ColorsTable,40
  69.  
  70.         ;*********************************************
  71.         ;****************Init Butttons****************
  72.         ;*********************************************
  73.  
  74.         mov ecx,[ColorsTable+8]
  75.         and ecx,0xffffff
  76.  
  77.         mov [Button1.type],byte 10010001b
  78.         mov [Button1.x],20
  79.         mov [Button1.y],50
  80.         mov [Button1.width],word 70
  81.         mov [Button1.height],word 20
  82.         mov [Button1.color1],dword ecx
  83.         mov [Button1.color2],dword 0xffffff
  84.         mov [Button1.text],text1
  85.  
  86.         push Button1
  87.         push Parend
  88.         call [craete_button]
  89.         mov [PointerToControlForButtonExit],eax
  90.  
  91.         mov ecx,[ColorsTable+8]
  92.         and ecx,0xffffff
  93.  
  94.         ;********************************************
  95.         ;***************Init EditBox*****************
  96.         ;********************************************
  97.  
  98.         mov ecx,[ColorsTable+8]
  99.         mov [EditBox.ed_flags],0b;1000000000000000b
  100.         mov [EditBox.ed_left],5   ;x
  101.         mov [EditBox.ed_top],10   ;y
  102.         mov [EditBox.ed_width],100
  103.         mov [EditBox.ed_height],14
  104.         mov [EditBox.ed_max],100
  105.         mov [EditBox.ed_text],buffer_for_text
  106.         mov [EditBox.ed_color],dword 0xffffff
  107.         mov [EditBox.shift_color],dword 0xaabbcc
  108.         mov [EditBox.ed_focus_border_color],0
  109.         mov [EditBox.ed_blur_border_color],ecx
  110.         mov [EditBox.ed_text_color],0
  111.  
  112.         push EditBox
  113.         push Parend
  114.         call [craete_edit_box]
  115.         mov [PointerToControlForEditBox],eax
  116.  
  117.         call draw_window
  118.  
  119.  
  120.         ;send message 1 for redrawing ALL controls
  121.         mov [Message],dword 1
  122.  
  123.         push Message
  124.         push Parend
  125.         call [send_message]
  126.  
  127. still:
  128.         mcall   10
  129.  
  130.         ;check for redraw window
  131.         cmp eax,1
  132.         jne no_window
  133.  
  134.           call draw_window
  135.  
  136.           mov [Message],dword 1
  137.           push Message
  138.           push Parend
  139.           call [send_message]
  140.  
  141.         jmp still
  142.         no_window:
  143.  
  144.         ;check for keys events
  145.         cmp eax,2
  146.         jne no_keys
  147.  
  148.           mcall   2
  149.           shr eax,8
  150.  
  151.           mov [Message],dword 2
  152.           mov [Message+4],eax
  153.  
  154.           push Message
  155.           push Parend
  156.           call [send_message]
  157.  
  158.           mov eax,[Message+4]
  159.  
  160.           cmp al,27
  161.           je exit
  162.  
  163.         jmp still
  164.         no_keys:
  165.  
  166.         ;check for pressed butons
  167.         cmp eax,3
  168.         jne no_buttons
  169.  
  170.           mcall   17
  171.           shr eax,8
  172.  
  173.         jmp still
  174.         no_buttons:
  175.  
  176.         ;check for mouse events
  177.         cmp eax,6
  178.         jne no_mouse
  179.  
  180.          mov [Message],dword 6
  181.  
  182.          mcall   37,1
  183.          mov ebx,eax
  184.          shr eax,16 ;x
  185.          and ebx,0xffff ;y
  186.  
  187.          mov [Message+4],eax
  188.          mov [Message+8],ebx
  189.  
  190.          mcall   37,2
  191.          mov [Message+12],eax
  192.  
  193.          ;send system events to control
  194.          push Message
  195.          push Parend
  196.          call [send_message]
  197.  
  198.          mov eax,[PointerToControlForButtonExit]
  199.  
  200.          xor ebx,ebx
  201.          mov bl,byte[eax+45]
  202.          cmp bl,11b
  203.          jne no_crossing_pressing_button
  204.  
  205.            mov [button_pressed],1
  206.  
  207.          no_crossing_pressing_button:
  208.  
  209.          xor ebx,ebx
  210.          mov bl,byte[eax+45]
  211.          cmp bl,1b
  212.          jne no_crossing_button
  213.  
  214.            cmp [button_pressed],1
  215.            jne no_crossing_button
  216.  
  217.               jmp exit
  218.  
  219.          no_crossing_button:
  220.  
  221.          jmp still
  222.          no_mouse:
  223.  
  224.         jmp still
  225.  
  226. exit:
  227.  
  228.         push [PointerToControlForButtonExit]
  229.         call [destroy_control]
  230.  
  231.         push [PointerToControlForEditBox]
  232.         call [destroy_control]
  233.  
  234.         mcall   -1
  235.  
  236.  
  237.  
  238. ;**********************************************
  239. ;*******************Draw window****************
  240. ;**********************************************
  241.  
  242. draw_window:
  243.  
  244.         mcall 12,1
  245.  
  246.         xor eax,eax
  247.         mov ebx,50
  248.         mov ecx,50
  249.         shl ebx,16
  250.         shl ecx,16
  251.         add ebx,120
  252.         add ecx,120
  253.         mov edx,0x03aabbcc
  254.         mov esi,0x805080d0
  255.         mov edi,0x005080d0
  256.         mcall
  257.  
  258.         mcall   12,2
  259.         ret
  260.  
  261.  
  262. GetPath:
  263.  
  264.         mov ebx,255
  265.         mov ecx,path
  266.  
  267.         next_symvol:
  268.         mov edx,ecx
  269.         add edx,ebx
  270.  
  271.         xor eax,eax
  272.         mov al,[edx]
  273.         cmp eax,'/'
  274.         je exit_path
  275.  
  276.         dec ebx
  277.         jnz next_symvol
  278.  
  279.         exit_path:
  280.  
  281.         inc edx
  282.         mov esi,dll_name
  283.         mov edi,edx
  284.         mov ecx,10
  285.         rep movsb
  286.  
  287.         ret
  288.  
  289.  
  290. include 'getproc.asm'
  291.  
  292. ;************************************************************
  293. ;***************************DATA*****************************
  294. ;************************************************************
  295.  
  296. align 4
  297.  
  298. dll_name        db 'libGUI.obj',0
  299. sys_libGUI_path db '/sys/lib/libGUI.obj',0
  300.  
  301. text1    db 'Exit',0
  302.  
  303. text_for_text db 'Hello world from zakladka',0
  304.  
  305. fnDestroyControl                     db 'DestroyControl',0
  306. fnSendMessage                        db 'SendMessage',0
  307. fnCraeteButton                       db 'CraeteButton',0
  308. fnCraeteEditbox                      db 'CraeteEditbox',0
  309.  
  310. myexport                             dd 0
  311.  
  312. destroy_control                      dd 0
  313. send_message                         dd 0
  314. craete_button                         dd 0
  315. craete_edit_box                       dd 0
  316.  
  317. PointerToControlForButtonExit        dd 0
  318.  
  319. PointerToControlForEditBox           dd 0
  320.  
  321. button_pressed                       dd 0
  322.  
  323. path                                 rb 256
  324.  
  325. Parend:        dd 0,0,0,0,0,0,0,0,0,0,0,0   ;44 bytes
  326. Message                               rd 4
  327.  
  328. ColorsTable  rd 10
  329. buffer_for_text rb 100+2
  330.  
  331. struc BUTTON
  332. {
  333.  .type             db 1
  334.  .flag             db 1
  335.  .x                dw 1
  336.  .y                dw 1
  337.  .width            dw 1
  338.  .height           dw 1
  339.  .image            dd 1
  340.  .imageX           dw 1
  341.  .imageY           dw 1
  342.  .imageSizeX       dw 1
  343.  .imageSizeY       dw 1
  344.  .transparentColor dd 1
  345.  .text             dd 1
  346.  .textX            dw 1
  347.  .textY            dw 1
  348.  .textcolor        dd 1
  349.  .color1           dd 1
  350.  .color2           dd 1
  351.  .mouseX           dw 1
  352.  .mouseY           dw 1
  353. }
  354.  
  355. struc EDITBOX
  356. {
  357.  .ed_width                      rd 1
  358.  .ed_left                       rd 1
  359.  .ed_top                        rd 1
  360.  .ed_color                      rd 1
  361.  .shift_color                   rd 1
  362.  .ed_focus_border_color         rd 1
  363.  .ed_blur_border_color          rd 1
  364.  .ed_text_color                 rd 1
  365.  .ed_max                        rd 1
  366.  .ed_text                       rd 1
  367.  .ed_flags                      rw 1
  368.  .ed_size                       rd 1
  369.  .ed_pos                        rd 1
  370.  .ed_offset                     rd 1
  371.  .cl_curs_x                     rd 1
  372.  .cl_curs_y                     rd 1
  373.  .ed_shift_pos                  rd 1
  374.  .ed_shift_pos_old              rd 1
  375.  .ed_height                     rd 1
  376.  .mouseX                        rd 1
  377.  .mouseY                        rd 1
  378. }
  379.  
  380. Button1             BUTTON
  381. EditBox             EDITBOX
  382.  
  383. i_end:
  384.