Box lib editbox: Difference between revisions

From KolibriOS wiki
Jump to navigation Jump to search
(translate box lib editbox wiki to english (some translations are incomplete))
 
(add example code)
 
Line 76: Line 76:
ed_mous_adn_b=        100011000b
ed_mous_adn_b=        100011000b
ed_mouse_on_off=1111111011111111b
ed_mouse_on_off=1111111011111111b
</syntaxhighlight>
==Example==
<syntaxhighlight lang="asm">use32                  ; use 32-bit command
; standard header
    db 'MENUET01'      ; signature
    dd 1              ; header version
    dd start          ; entry point
    dd i_end          ; initialized size
    dd mem            ; required memory
    dd mem            ; stack pointer
    dd 0              ; parameters
    dd cur_dir_path    ; path
include 'macros.inc'
include 'proc32.inc'
include 'dll.inc'
include 'box_lib.mac'
start:
    ; load libraries
    stdcall dll.Load, @IMPORT_BOXLIB
    test    eax, eax
    jnz    exit
    mcall  40,0x27          ;set up a mask for expected events
red_win:
    call    draw_window      ;initially it is necessary to draw a box
align 4
still:
    mcall    10              ;notifies of an event
    dec      eax
    jz      red_win
    dec      eax
    jz      key
    dec      eax
    jz      button
    push    dword edit1
    call    [edit_box_mouse]
    jmp    still
button:
    mcall  17            ;receive identifier of the pressed key
    test    ah,ah
    jz      still
exit:
    mcall  -1
key:
    mcall  2              ;get the code of the pressed key
    push    dword edit1
    call    [edit_box_key]
    jmp    still
align 4
draw_window:                ;draw application window
    mcall  12,1
    mcall  0,<320,190>,<300,75>,0x33AABBCC,0x805080DD,hed
    push    dword edit1
    call    [edit_box_draw]
    mcall  12,2
  ret
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
hed db 'edit_box example',0
edit1 edit_box 165,10,10,0xffffff,0x6f9480,0,0xAABBCC,0,308,username_buffer,mouse_dd,ed_focus
align 4
@IMPORT_BOXLIB:
library box_lib, 'box_lib.obj'
import  box_lib, \
        edit_box_draw,  'edit_box', \
        edit_box_key,  'edit_box_key', \
        edit_box_mouse, 'edit_box_mouse', \
        version_ed,    'version_ed'
username_buffer    rb 100
;-----------------------
mouse_dd        rd 1
cur_dir_path    rb 4096
i_end:
rb 1024
mem:
</syntaxhighlight>
</syntaxhighlight>


[[Category:Libraries]]
[[Category:Libraries]]

Latest revision as of 13:43, 24 July 2016

Introduction

Text field is used when entering text/numeric information.

Functions

  • edit_box_key - this function should be called when you enter the information from the keyboard
  • edit_box_mouse - this function should be called when you enter the information from the mouse
  • edit_box_draw - this function should be called when redrawing.
  • edit_box_set_text - it copies the text from the cursor in the text box. If the text in the index is longer than allowed in edit_box element, it is written not all. After calling this function, you need to redraw the window function edit_box_draw, otherwise the changes are not immediately visible. Example of use:
push dword buf
push dword edit1
call dword [edit_box_set_text]
.........
buf db '111-222-333', 0

where edit1 - edit_box structure element; buf - buffer, which contains the text of the installed.

  • version_ed - version element

editbox structure

editbox structure size is set within box_lib.mac file in ed_struc_size parameter.

struc  edit_box width,left,top,color,shift_color,focus_border_color,\
       blur_border_color,text_color,max,text,mouse_variable,flags,size,pos
{
.width dd width
.left  dd left
.top   dd top
.color dd color
.shift_color dd shift_color
.focus_border_color dd focus_border_color
.blur_border_color  dd blur_border_color
.text_color dd text_color
.max  dd max
.text dd text
.mouse_variable dd mouse_variable
.flags  dd flags+0
.size   dd size+0
.pos    dd pos+0
.offset dd 0
.cl_curs_x dd 0
.cl_curs_y dd 0
.shift     dd 0
.shift_old dd 0
}
  • width - width of the element
  • left - the left margin
  • top - the top margin
  • color - background color
  • shift_color - color selection by holding [Shift] or mouse
  • focus_border_color - frame color when the field is in focus
  • blur_border_color - frame color when the field is not in focus
  • text_color
  • max - the maximum size of the text (должно быть +2 резервных символа)
  • size - the current length of the text

Flags

ed_figure_only= 1000000000000000b   ;some characters
ed_always_focus= 100000000000000b
ed_focus=                     10b   ;application focus
ed_pass=                       1b   ;password field
ed_shift_on=                1000b   ;если не установлен -значит впервые нажат shift,если был установлен, значит мы уже что - то делали удерживая shift
ed_shift_on_off=1111111111110111b
ed_shift=                    100b   ;включается при нажатии на shift т.е. если нажимаю
ed_shift_off=   1111111111111011b
ed_shift_bac=              10000b   ;бит для очистки выделеного shift т.е. при установке говорит что есть выделение
ed_shift_bac_cl=1111111111101111b   ;очистка при удалении выделения
ed_shift_cl=    1111111111100011b
ed_shift_mcl=   1111111111111011b
ed_left_fl=               100000b
ed_right_fl=    1111111111011111b
ed_offset_fl=            1000000b
ed_offset_cl=   1111111110111111b
ed_insert=              10000000b
ed_insert_cl=   1111111101111111b
ed_mouse_on =          100000000b
ed_mous_adn_b=         100011000b
ed_mouse_on_off=1111111011111111b

Example

use32                  ; use 32-bit command
; standard header
    db 'MENUET01'      ; signature
    dd 1               ; header version
    dd start           ; entry point
    dd i_end           ; initialized size
    dd mem             ; required memory
    dd mem             ; stack pointer
    dd 0               ; parameters
    dd cur_dir_path    ; path

include 'macros.inc'
include 'proc32.inc'
include 'dll.inc'
include 'box_lib.mac'

start:
    ; load libraries
    stdcall dll.Load, @IMPORT_BOXLIB
    test    eax, eax
    jnz     exit
    mcall   40,0x27           ;set up a mask for expected events

red_win:
    call     draw_window      ;initially it is necessary to draw a box

align 4
still:
    mcall    10               ;notifies of an event
    dec      eax
    jz       red_win
    dec      eax
    jz       key
    dec      eax
    jz       button

    push    dword edit1
    call    [edit_box_mouse]

    jmp     still

button:
    mcall   17             ;receive identifier of the pressed key
    test    ah,ah
    jz      still

exit:
    mcall   -1

key:
    mcall   2              ;get the code of the pressed key

    push    dword edit1
    call    [edit_box_key]

    jmp     still

align 4
draw_window:                ;draw application window
    mcall   12,1
    mcall   0,<320,190>,<300,75>,0x33AABBCC,0x805080DD,hed

    push    dword edit1
    call    [edit_box_draw]

    mcall   12,2
   ret

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

hed db 'edit_box example',0

edit1 edit_box 165,10,10,0xffffff,0x6f9480,0,0xAABBCC,0,308,username_buffer,mouse_dd,ed_focus

align 4
@IMPORT_BOXLIB:

library box_lib, 'box_lib.obj'

import  box_lib, \
        edit_box_draw,  'edit_box', \
        edit_box_key,   'edit_box_key', \
        edit_box_mouse, 'edit_box_mouse', \
        version_ed,     'version_ed'

username_buffer    rb 100
;-----------------------

mouse_dd        rd 1
cur_dir_path    rb 4096
i_end:
rb 1024
mem: