Subversion Repositories Kolibri OS

Rev

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

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