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 Image 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      7*1024+100
  14.         dd      7*1024+100
  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 [crate_button],eax
  58.  
  59.         push fnCraeteImage
  60.         push [myexport]
  61.         call _ksys_cofflib_getproc
  62.         mov [crate_image],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],10
  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 [crate_button]
  89.         mov [PointerToControlForButtonExit],eax
  90.  
  91.         ;********************************************
  92.         ;******************Init Image****************
  93.         ;********************************************
  94.  
  95.         mov [Image.type],byte 10000000b
  96.         mov [Image.x],25
  97.         mov [Image.y],5
  98.         mov [Image.sizex],40
  99.         mov [Image.sizey],40
  100.         mov [Image.pointer],Picture
  101.  
  102.         push Image
  103.         push Parend
  104.         call [crate_image]
  105.         mov [PointerToControlForImage],eax
  106.  
  107.         call draw_window
  108.  
  109.         ;send message 1 for redrawing ALL controls
  110.         mov [Message],dword 1
  111.  
  112.         push Message
  113.         push Parend
  114.         call [send_message]
  115.  
  116. still:
  117.         mcall   10
  118.  
  119.         ;check for redraw window
  120.         cmp eax,1
  121.         jne no_window
  122.  
  123.           call draw_window
  124.  
  125.           mov [Message],1
  126.  
  127.           push Message
  128.           push Parend
  129.           call [send_message]
  130.  
  131.         jmp still
  132.         no_window:
  133.  
  134.         ;check for keys events
  135.         cmp eax,2
  136.         jne no_keys
  137.  
  138.           mcall   2
  139.           shr eax,8
  140.  
  141.           mov [Message],dword 2
  142.           mov [Message+4],eax
  143.  
  144.           push Message
  145.           push Parend
  146.           call [send_message]
  147.  
  148.           mov eax,[Message+4]
  149.  
  150.           cmp al,27
  151.           je exit
  152.  
  153.         jmp still
  154.         no_keys:
  155.  
  156.         ;check for pressed butons
  157.         cmp eax,3
  158.         jne no_buttons
  159.  
  160.           mcall   17
  161.           shr eax,8
  162.  
  163.         jmp still
  164.         no_buttons:
  165.  
  166.         ;check for mouse events
  167.         cmp eax,6
  168.         jne no_mouse
  169.  
  170.          mov [Message],dword 6
  171.  
  172.          mcall   37,1
  173.          mov ebx,eax
  174.          shr eax,16 ;x
  175.          and ebx,0xffff ;y
  176.  
  177.          mov [Message+4],eax
  178.          mov [Message+8],ebx
  179.  
  180.          mcall   37,2
  181.          mov [Message+12],eax
  182.  
  183.          ;send system events to control
  184.          push Message
  185.          push Parend
  186.          call [send_message]
  187.  
  188.          mov eax,[PointerToControlForButtonExit]
  189.  
  190.          xor ebx,ebx
  191.          mov bl,byte[eax+45]
  192.          cmp bl,11b
  193.          jne no_crossing_pressing_button
  194.  
  195.            mov [button_pressed],1
  196.  
  197.          no_crossing_pressing_button:
  198.  
  199.          xor ebx,ebx
  200.          mov bl,byte[eax+45]
  201.          cmp bl,1b
  202.          jne no_crossing_button
  203.  
  204.            cmp [button_pressed],1
  205.            jne no_crossing_button
  206.  
  207.               jmp exit
  208.  
  209.          no_crossing_button:
  210.  
  211.          jmp still
  212.          no_mouse:
  213.  
  214.         jmp still
  215.  
  216. exit:
  217.  
  218.         push [PointerToControlForButtonExit]
  219.         call [destroy_control]
  220.  
  221.         push [PointerToControlForImage]
  222.         call [destroy_control]
  223.  
  224.         mcall   -1
  225.  
  226.  
  227.  
  228. ;**********************************************
  229. ;*******************Draw window****************
  230. ;**********************************************
  231.  
  232. draw_window:
  233.  
  234.         mcall   12,1
  235.  
  236.         xor eax,eax
  237.         mov ebx,50
  238.         mov ecx,50
  239.         shl ebx,16
  240.         shl ecx,16
  241.         add ebx,100
  242.         add ecx,100
  243.         mov edx,0x03aabbcc
  244.         mov esi,0x805080d0
  245.         mov edi,0x005080d0
  246.         mcall
  247.  
  248.         mcall   12,2
  249.         ret
  250.  
  251.  
  252. GetPath:
  253.  
  254.         mov ebx,255
  255.         mov ecx,path
  256.  
  257.         next_symvol:
  258.         mov edx,ecx
  259.         add edx,ebx
  260.  
  261.         xor eax,eax
  262.         mov al,[edx]
  263.         cmp eax,'/'
  264.         je exit_path
  265.  
  266.         dec ebx
  267.         jnz next_symvol
  268.  
  269.         exit_path:
  270.  
  271.         inc edx
  272.         mov esi,dll_name
  273.         mov edi,edx
  274.         mov ecx,10
  275.         rep movsb
  276.  
  277.         ret
  278.  
  279.  
  280. include 'getproc.asm'
  281.  
  282. ;************************************************************
  283. ;***************************DATA*****************************
  284. ;************************************************************
  285.  
  286. align 4
  287.  
  288. dll_name        db 'libGUI.obj',0
  289. sys_libGUI_path db '/sys/lib/libGUI.obj',0
  290.  
  291. text1    db 'Exit',0
  292.  
  293. fnDestroyControl                     db 'DestroyControl',0
  294. fnSendMessage                        db 'SendMessage',0
  295. fnCraeteButton                       db 'CraeteButton',0
  296. fnCraeteImage                        db 'CraeteImage',0
  297.  
  298. myexport                             dd 0
  299.  
  300. destroy_control                      dd 0
  301. send_message                         dd 0
  302. crate_button                         dd 0
  303. crate_image                          dd 0
  304.  
  305. PointerToControlForButtonExit        dd 0
  306.  
  307. PointerToControlForImage             dd 0
  308.  
  309. button_pressed                       dd 0
  310.  
  311. path                                 rb 256
  312.  
  313. Parend:        dd 0,0,0,0,0,0,0,0,0,0,0,0   ;44 bytes
  314. Message                               rd 4
  315.  
  316. ColorsTable  rd 10
  317.  
  318. struc BUTTON
  319. {
  320.  .type             db 1
  321.  .flag             db 1
  322.  .x                dw 1
  323.  .y                dw 1
  324.  .width            dw 1
  325.  .height           dw 1
  326.  .image            dd 1
  327.  .imageX           dw 1
  328.  .imageY           dw 1
  329.  .imageSizeX       dw 1
  330.  .imageSizeY       dw 1
  331.  .transparentColor dd 1
  332.  .text             dd 1
  333.  .textX            dw 1
  334.  .textY            dw 1
  335.  .textcolor        dd 1
  336.  .color1           dd 1
  337.  .color2           dd 1
  338.  .mouseX           dw 1
  339.  .mouseY           dw 1
  340. }
  341.  
  342. struc IMAGE
  343. {
  344.  .type             rb 1
  345.  .flag             rb 1
  346.  .color            rd 1
  347.  .x                rd 1
  348.  .y                rd 1
  349.  .sizex            rd 1
  350.  .sizey            rd 1
  351.  .pointer          rd 1
  352. }
  353.  
  354. Button1             BUTTON
  355. Image               IMAGE
  356.  
  357. untibug: rb 1000
  358.  
  359. Picture:
  360. file 'koslogo.raw'
  361.  
  362. i_end:
  363.