Subversion Repositories Kolibri OS

Rev

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

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