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 Scroller from libGUI
  4. ;
  5. ;
  6.  
  7. control_hader_size           =  44
  8. control_scroller_data_size   =  29
  9. control_button_data_size     =  50
  10.  
  11. first_child_button_pressed   =  1b
  12. second_child_button_pressed  =  10000b
  13.  
  14.  
  15. include 'macros.inc'
  16. use32
  17.         db      'MENUET01'
  18.         dd      1
  19.         dd      start
  20.         dd      i_end
  21.         dd      4000
  22.         dd      4000
  23.         dd      0
  24.         dd      path
  25.  
  26. start:
  27.         ;init hepe of memory
  28.         mcall   68,11
  29.         ;set current dir as ./
  30.         call GetPath
  31.  
  32.         ;load dll
  33.         mcall   68,19,path
  34.  
  35.         test    eax,eax
  36.         jnz     libGUI_loaded
  37.  
  38.           ;load dll from system directory
  39.           mcall 68,19,sys_dll_path
  40.  
  41.           test eax,eax
  42.           jnz libGUI_loaded
  43.  
  44.             mcall -1
  45.  
  46.         libGUI_loaded:
  47.  
  48.         mov [myexport],eax
  49.  
  50.         ;load dll functions
  51.  
  52.         push fnDestroyControl
  53.         push [myexport]
  54.         call _ksys_cofflib_getproc
  55.         mov [destroy_control],eax
  56.  
  57.         push fnSendMessage
  58.         push [myexport]
  59.         call _ksys_cofflib_getproc
  60.         mov [send_message],eax
  61.  
  62.         push fnCraeteButton
  63.         push [myexport]
  64.         call _ksys_cofflib_getproc
  65.         mov [craete_button],eax
  66.  
  67.         push fnCraeteScroller
  68.         push [myexport]
  69.         call _ksys_cofflib_getproc
  70.         mov [craete_scroller],eax
  71.  
  72.  
  73.         ;set events mask
  74.         mcall   40,1100111b
  75.  
  76.         ;get standart colors table
  77.         mcall   48,3,ColorsTable,40
  78.  
  79.         ;*********************************************
  80.         ;****************Init Butttons****************
  81.         ;*********************************************
  82.  
  83.         mov ecx,[ColorsTable+8]
  84.         and ecx,0xffffff
  85.  
  86.         mov [ButtonExit.type],byte 10010001b
  87.         mov [ButtonExit.x],90
  88.         mov [ButtonExit.y],160
  89.         mov [ButtonExit.width],word 70
  90.         mov [ButtonExit.height],word 20
  91.         mov [ButtonExit.color1],dword ecx
  92.         mov [ButtonExit.color2],dword 0xffffff
  93.         mov [ButtonExit.text],text
  94.  
  95.  
  96.         push ButtonExit
  97.         push Parend
  98.         call [craete_button]
  99.         mov [PointerToControlForButtonExit],eax
  100.  
  101.          mov ecx,[ColorsTable+8]
  102.          and ecx,0xffffff
  103.  
  104.         ;********************************************
  105.         ;***************Init scrollers****************
  106.         ;********************************************
  107.  
  108.         ;init vertical scroller
  109.         mov ecx,[ColorsTable+8]
  110.         mov [VerticalScroller.type],byte 11100001b
  111.         mov [VerticalScroller.x],10
  112.         mov [VerticalScroller.y],30
  113.         mov [VerticalScroller.pos],0.2
  114.         mov [VerticalScroller.length],200
  115.         mov [VerticalScroller.size],0.9
  116.         mov [VerticalScroller.color1],ecx
  117.  
  118.  
  119.         push VerticalScroller
  120.         push Parend
  121.         call [craete_scroller]
  122.         mov [PointerToControlForVerticalScroller],eax
  123.  
  124.         ;init horizontal scroller
  125.         mov ecx,[ColorsTable+8]
  126.         mov [HorizontalScroller.type],byte 11110010b
  127.         mov [HorizontalScroller.x],30
  128.         mov [HorizontalScroller.y],30
  129.         mov [HorizontalScroller.pos],0.7
  130.         mov [HorizontalScroller.length],200
  131.         mov [HorizontalScroller.size],0.3
  132.         mov [HorizontalScroller.color1],0xaabbccff;ecx
  133.  
  134.         push HorizontalScroller
  135.         push Parend
  136.         call [craete_scroller]
  137.         mov [PointerToControlForHorizontalScroller],eax
  138.  
  139.         call draw_window
  140.  
  141.         ;send message 1 for redrawing ALL controls
  142.         mov [Message],dword 1
  143.  
  144.         push Message
  145.         push Parend
  146.         call [send_message]
  147.  
  148. still:
  149.         mcall   10
  150.  
  151.         mov [SystemEvent],eax
  152.  
  153.         ;-----------------------
  154.         ;check for redraw window
  155.         ;-----------------------
  156.  
  157.         cmp eax,1
  158.         jne no_window
  159.  
  160.           call draw_window
  161.  
  162.           mov [Message],dword 1
  163.  
  164.           push Message
  165.           push Parend
  166.           call [send_message]
  167.  
  168.           jmp still
  169.         no_window:
  170.  
  171.         ;---------------------
  172.         ;check for keys events
  173.         ;---------------------
  174.  
  175.         cmp eax,2
  176.         jne no_keys
  177.  
  178.         mcall   2
  179.           shr eax,8
  180.  
  181.           mov [Message],dword 2
  182.           mov [Message+4],eax
  183.  
  184.           push Message
  185.           push Parend
  186.           call [send_message]
  187.  
  188.           mov eax,[Message+4]
  189.  
  190.           cmp al,27
  191.           je exit
  192.  
  193.           jmp still
  194.         no_keys:
  195.  
  196.         ;-------------------------
  197.         ;check for events of mouse
  198.         ;-------------------------
  199.  
  200.         cmp eax,3
  201.         jne no_button_close_window
  202.  
  203.  
  204.         mcall   17
  205.         shr eax,8
  206.  
  207.         jmp still
  208.         no_button_close_window:
  209.  
  210.         ;check for mouse events
  211.         cmp eax,6
  212.         jne no_mouse
  213.  
  214.          ;craete message of mouse for controls
  215.          mov [Message],dword 6
  216.  
  217.          mcall   37,1
  218.          mov ebx,eax
  219.          shr eax,16 ;x
  220.          and ebx,0xffff ;y
  221.  
  222.          mov [Message+4],eax
  223.          mov [Message+8],ebx
  224.  
  225.          mcall   37,2
  226.          mov [Message+12],eax
  227.  
  228.          ;send message to controls
  229.          push Message
  230.          push Parend
  231.          call [send_message]
  232.  
  233.          ;interraction with button exit
  234.          ;copy data of scroller of button from control to structure
  235.  
  236.          mov esi,[PointerToControlForButtonExit]
  237.          add esi,control_hader_size
  238.          mov edi,ButtonExit
  239.          mov ecx,control_button_data_size
  240.          rep movsb
  241.  
  242.          xor eax,eax
  243.          mov al,[ButtonExit.flag]
  244.  
  245.          ;check button for pressing
  246.          and al,10b
  247.          test al,al
  248.          jz button_3_not_pressed
  249.  
  250.            mov [button_pressed],1
  251.  
  252.          jmp no_pressed_button
  253.  
  254.          button_3_not_pressed:
  255.  
  256.          cmp [button_pressed],1
  257.          jne no_pressed_button
  258.  
  259.              jmp exit
  260.          no_pressed_button:
  261.  
  262.          ;interraction with vertical scroller
  263.  
  264.          ;copy data of vertical scroller from control to structure
  265.  
  266.          mov esi,[PointerToControlForVerticalScroller]
  267.          add esi,control_hader_size
  268.          mov edi,VerticalScroller
  269.          mov ecx,control_scroller_data_size
  270.          rep movsb
  271.  
  272.          mov eax,[VerticalScroller.pos]
  273.          mov [PosY_float],eax  ;position of scroll bar  from 0...1
  274.  
  275.          xor edx,edx
  276.          call DrawRectangle
  277.  
  278.          xor eax,eax
  279.          mov ax,[VerticalScroller.buttons_flags]
  280.          and ax,first_child_button_pressed
  281.          test ax,ax
  282.          jz vertical_first_child_button_not_pressed
  283.  
  284.            mov edx,0xff00
  285.            call DrawRectangle
  286.  
  287.          vertical_first_child_button_not_pressed:
  288.  
  289.  
  290.          xor eax,eax
  291.          mov ax,[VerticalScroller.buttons_flags]
  292.          and ax,second_child_button_pressed
  293.          test ax,ax
  294.          jz vertical_second_child_button_not_pressed
  295.  
  296.            mov edx,0xff
  297.            call DrawRectangle
  298.  
  299.          vertical_second_child_button_not_pressed:
  300.  
  301.          ;interraction with horizontal scroller
  302.  
  303.          ;copy data of horizontal scroller from control to structure
  304.  
  305.          mov esi,[PointerToControlForHorizontalScroller]
  306.          add esi,control_hader_size
  307.          mov edi,HorizontalScroller
  308.          mov ecx,control_scroller_data_size
  309.          rep movsb
  310.  
  311.          xor eax,eax
  312.          mov ax,[HorizontalScroller.buttons_flags]
  313.          and ax,first_child_button_pressed
  314.          test ax,ax
  315.          jz horizontal_first_child_button_not_pressed
  316.  
  317.            mov edx,0xffffff
  318.            call DrawRectangle
  319.  
  320.          horizontal_first_child_button_not_pressed:
  321.  
  322.          xor eax,eax
  323.          mov ax,[HorizontalScroller.buttons_flags]
  324.          and ax,second_child_button_pressed
  325.          test ax,ax
  326.          jz horizontal_second_child_button_not_pressed
  327.  
  328.            mov edx,0xff0000
  329.            call DrawRectangle
  330.  
  331.          horizontal_second_child_button_not_pressed:
  332.  
  333.          jmp still
  334.          no_mouse:
  335.  
  336.         jmp still
  337.  
  338. exit:
  339.  
  340.         ;free resourses
  341.         push [PointerToControlForVerticalScroller]
  342.         call [destroy_control]
  343.  
  344.         push [PointerToControlForHorizontalScroller]
  345.         call [destroy_control]
  346.  
  347.         push [PointerToControlForButtonExit]
  348.         call [destroy_control]
  349.  
  350.         mcall   -1
  351.  
  352. ;**********************************************
  353. ;*******************Draw window****************
  354. ;**********************************************
  355.  
  356. draw_window:
  357.  
  358.         mcall   12,1
  359.  
  360.         xor eax,eax
  361.         mov ebx,50
  362.         mov ecx,50
  363.         shl ebx,16
  364.         shl ecx,16
  365.         add ebx,280
  366.         add ecx,280
  367.         mov edx,0x03aabbcc
  368.         mov esi,0x805080d0
  369.         mov edi,0x005080d0
  370.         mcall
  371.  
  372.         mcall   12,2
  373.         ret
  374.  
  375.  
  376. GetPath:
  377.  
  378.         mov ebx,255
  379.         mov ecx,path
  380.  
  381.         next_symvol:
  382.         mov edx,ecx
  383.         add edx,ebx
  384.  
  385.         xor eax,eax
  386.         mov al,[edx]
  387.         cmp eax,'/'
  388.         je exit_path
  389.  
  390.         dec ebx
  391.         jnz next_symvol
  392.  
  393.         exit_path:
  394.  
  395.         inc edx
  396.         mov esi,dll_name
  397.         mov edi,edx
  398.         mov ecx,10
  399.         rep movsb
  400.  
  401.         ret
  402.  
  403. DrawRectangle:
  404.  
  405.         mov eax,13
  406.         mov ebx,100*65536+50
  407.         mov ecx,100*65536+50
  408.         int 0x40
  409.  
  410.         ret
  411.  
  412. include 'getproc.asm'
  413.  
  414. ;************************************************************
  415. ;***************************DATA*****************************
  416. ;************************************************************
  417.  
  418. align 4
  419.  
  420. dll_name      db 'libGUI.obj',0
  421. sys_dll_path  db '/sys/lib/libGUI.obj',0
  422.  
  423. text          db 'Exit',0
  424.  
  425. fnDestroyControl                     db 'DestroyControl',0
  426. fnSendMessage                        db 'SendMessage',0
  427. fnCraeteButton                       db 'CraeteButton',0
  428. fnCraeteScroller                     db 'CraeteScroller',0
  429.  
  430. myexport                             dd 0
  431.  
  432. destroy_control                      dd 0
  433. send_message                         dd 0
  434. craete_button                         dd 0
  435. craete_scroller                        dd 0
  436.  
  437. PointerToControlForButtonExit        dd 0
  438.  
  439. PointerToControlForHorizontalScroller dd 0
  440. PointerToControlForVerticalScroller   dd 0
  441.  
  442.  
  443. SystemEvent                          dd 0
  444.  
  445. PosX_float                           dd 0
  446. PosY_float                           dd 0
  447.  
  448.  
  449. button_pressed                       dd 0
  450.  
  451. IPC_table                            rd 256
  452. path                                 rb 256
  453. ColorsTable                          rd 10
  454.  
  455. Parend:    dd 0,0,0,0,0,0,0,0,0,0,0,0   ;44 bytes
  456. Message                              rd 4
  457. x                                    dd 0
  458. y                                    dd 0
  459. number                               dd 0
  460.  
  461. struc BUTTON
  462. {
  463.  .type             db 1
  464.  .flag             db 1
  465.  .x                dw 1
  466.  .y                dw 1
  467.  .width            dw 1
  468.  .height           dw 1
  469.  .image            dd 1
  470.  .imageX           dw 1
  471.  .imageY           dw 1
  472.  .imageSizeX       dw 1
  473.  .imageSizeY       dw 1
  474.  .transparentColor dd 1
  475.  .text             dd 1
  476.  .textX            dw 1
  477.  .textY            dw 1
  478.  .textcolor        dd 1
  479.  .color1           dd 1
  480.  .color2           dd 1
  481.  .mouseX           dw 1
  482.  .mouseY           dw 1
  483. }
  484.  
  485. struc SCROLLER
  486. {
  487.  .type             rb 1
  488.  .x                rw 1
  489.  .y                rw 1
  490.  .length           rw 1
  491.  .color1           rd 1
  492.  .size             rd 1
  493.  .pos              rd 1
  494.  .buttons_flags    rw 1
  495.  .ChildButton1     rd 1
  496.  .ChildButton2     rd 1
  497.  .mouseX           rw 1
  498.  .mouseY           rw 1
  499. }
  500.  
  501. ButtonExit          BUTTON
  502. VerticalScroller     SCROLLER
  503. HorizontalScroller   SCROLLER
  504.  
  505.  
  506. i_end: