Subversion Repositories Kolibri OS

Rev

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

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