Subversion Repositories Kolibri OS

Rev

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