again modified.
Code: Select all
/*
COLOURS used in code
'c'-description
'y'-testing
'b'-defining
'g' customizing layout
''
*/
'c'============================
'*******************
'*** inputfield(keyboard_layout$,sepstring$) ***
'*******************
'owns all variables
'creates array
'keyboard_layout$: contains layout/single keys of keyboard, separator$ is the character used for separation
'each row contains two equal number of keys/characters, where the first entry corresponds to the normal layout,
'the second, separated by sepstring$, corresponds to the layout activated by caps-lock (here:∆ used for toggeling between normal and caps-layout)
'the next row is separated by sepstring$ from the previous row
'caps-lock (here:∆) used for toggeling between normal and caps-layout
'long keys can be defined as double-, tripple- etc. keys.
'============================
'b'
DEF inputfield(keyboard_layout$,sepstring$)
'g'
'variables
key_width=70 ! key_height=70 'size of keys in pixles
x_keygap=key_width*.1 ! y_keygap=key_height*.1 'gap between keys in pixles
caps=1 'initial caps-status
'b'
'IF NOT called THEN 'if called for the first time
DIM key$(20,20,3)
DIM keyboard_width(20)
keyboard_height=0 'resetting keyboard_height. beeing filled later...
'g'
keyrow_central=1 'all keys are centrally positioned. 0: keys are vertically alligned to the left
drawframe=1 'draws frame around inputpad
'b'
key_y=1'counting keyboard->row
keyboard_max_width=0 'maximum width of all keyboard rows (for frame e.g.)
'setting up key$(column, row, caps(1..2))
FOR read_row=1 TO lensepstr(keyboard_layout$,sepstring$) STEP 2
key_data1$=insepstr$(read_row,keyboard_layout$,sepstring$)
key_data2$=insepstr$(read_row+1,keyboard_layout$,sepstring$)
keyboard_width(key_y)=LEN(key_data1$)
IF keyboard_width(key_y)>keyboard_max_width THEN keyboard_max_width=keyboard_width(key_y)
string_to_3d_array_x(key$,1,key_y,1,key_data1$)'fills string in key$ over running xstarting by 1, y=key_y, z=1(cap=0)
string_to_3d_array_x(key$,1,key_y,2,key_data2$)'s, above with z=2(cap=1)
key_y+=1
NEXT read_row
keyboard_height=key_y-1
'END IF 'called?
'called=1
END DEF 'of infofield
'c'============================
'********************************
'*** inputfield_create(x1,y1,caps) ***
'********************************
'creates keyboard graphic
'x1, x2: Position of upper left corner
'caps:status of caps-function (1:normal character, 2: capital character)
'============================
'b'
DEF inputfield_create(x1,y1,caps)
doubled_letter=0
' IF NOT called THEN
drawframe=inputfield.drawframe
keyrow_central=inputfield.keyrow_central
keyboard_max_width=inputfield.keyboard_max_width
inputfield.x1=x1 ! inputfield.y1=y1
keyboard_height=inputfield.keyboard_height 'keyboard_width()=inputfield.keyboard_width() doesnt work - array!!
key_width=inputfield.key_width ! key_height=inputfield.key_height
x_keygap=inputfield.x_keygap ! y_keygap=inputfield.y_keygap
'ENDIF 'not called
'draw frame
IF drawframe THEN
FILL COLOR 0,0,0
FILL RECT x1,y1 TO x1+keyboard_max_width*key_width,y1+key_height*keyboard_height
DRAW RECT x1,y1 TO x1+keyboard_max_width*key_width,y1+key_height*keyboard_height
ENDIF
'building up keys
FOR key_y=1 TO keyboard_height
last_key_in_row=0 ! doubled_letter=0
IF KEYrow_central THEN keyrow_centr_offset=(keyboard_max_width-inputfield.keyboard_width(key_y))*key_width/2 ELSE keyrow_centr_offset=0
FOR key_x=1 TO inputfield.keyboard_width(key_y)
current_letter$=inputfield.key$(key_x,key_y,caps)
IF key_x<inputfield.keyboard_width(key_y) THEN 'if not last key in row
next_letter$=inputfield.key$(key_x+1,key_y,caps)
ELSE 'last key in row
last_key_in_row=1
next_letter$=""
ENDIF
xl=gridcoord(key_x-1,key_width,x1)+x_keygap 'vertical left line
xr=gridcoord(key_x,key_width,x1)-x_keygap 'vertical right line
yu=gridcoord(key_y-1,key_height,y1)+y_keygap 'horizontal upper line
yd=gridcoord(key_y,key_height,y1)-y_keygap 'horizontal lower line
xc=gridcoord(key_x-1,key_width,x1)+key_width/2 'center_x
yc=gridcoord(key_y-1,key_height,y1)+key_height/2 'center_y
IF next_letter$=current_letter$ THEN
IF doubled_letter=0 THEN 'begin doubled letter
xl_doubled_letter=xl 'keep first x-position in mind
doubled_letter=1 'doubled_letter_modus on
ELSE 'doubled_letter=1
IF last_key_in_row THEN
'DRAW RECT xl_doubled_letter+keyrow_centr_offset,yu TO xr+keyrow_centr_offset,yd 'end of row
doubled_letter=0
ENDIF
double_letter=1
ENDIF
ELSE 'next_letter<>current_letter
IF doubled_letter=1 THEN
xc_double=xl_doubled_letter+(doubled_letter_count+2)*key_width/2 'center_x when doubled keys
DRAW RECT xl_doubled_letter+keyrow_centr_offset,yu TO xr+keyrow_centr_offset,yd 'doubled_letter end
'DRAW CIRCLE xl_doubled_letter+keyrow_centr_offset+((xr+keyrow_centr_offset)-(xl_doubled_letter+keyrow_centr_offset))/2,yc SIZE 1
DRAW TEXT current_letter$ AT xl_doubled_letter+keyrow_centr_offset+((xr+keyrow_centr_offset)-(xl_doubled_letter+keyrow_centr_offset))/2,yc
doubled_letter=0
ELSE 'doubled_letter=0
DRAW RECT xl+keyrow_centr_offset,yu TO xr+keyrow_centr_offset,yd 'draws outer boundry '
'DRAW CIRCLE xc+keyrow_centr_offset,yc SIZE 1
DRAW TEXT current_letter$ AT xc+keyrow_centr_offset,yc
ENDIF
ENDIF
last_letter$=inputfield.key$(key_x,key_y,caps)
NEXT key_x
NEXT key_y
' called=1
END DEF 'of inputfield_create
'c'============================
'*********************************
'*** inputfield_identify$(caps) ***
'*********************************
'waits for touch and identifies pressed key
'x,y: coordinate of a-system
'caps:status of caps-function
'============================
'b'
DEF inputfield_identify$(caps)
IF NOT called THEN
KEYrow_CENTRAL=inputfield.KEYrow_CENTRAL
key_width=inputfield.key_width ! key_height=inputfield.key_height
x1=inputfield.x1 ! y1=inputfield.y1
keyboard_max_width=inputfield.keyboard_max_width
ENDIF 'not called
main_loop1:
DO
SLOWDOWN
GET TOUCH 0 AS x,y 'get touch
UNTIL x>-1
DO
GET TOUCH 0 AS x0,y0
UNTIL x0=-1 'touch released?
key_y=gridpos_f(y,key_height,y1)+1
'calculate key_offset_position IF keyboard-design is set to central
IF KEYrow_central THEN keyrow_centr_offset=(keyboard_max_width-inputfield.keyboard_width(key_y))*key_width/2 ELSE keyrow_centr_offset=0
key_x=gridpos_f(x,key_width,x1+keyrow_centr_offset)+1
RETURN inputfield.key$(key_x,key_y,caps)
called = 1
END DEF
'c'============================
' ****** string_to_3d_array_x(array$(,,),x_start,dim_y,dim_z,string$) ******
'imports a string letterwise into an array, where x-Dimension is variable and y,z is steady
'Syntax: (array$(,,): array, where string$ is imported, x_start: index of x where first letter is imported
'dim_y, dim_z: steady index, string$: string to be imported
'============================
'b'
DEF string_to_3d_array_x(array$(,,),x_start,dim_y,dim_z,string$)
FOR n= x_start TO LEN(string$)
array$(n,dim_y,dim_z)=MID$(string$,n-1+OPTION_BASE(),1)
NEXT n
END DEF
'c'============================
'********************************
'*** gridcoord(n,grid,anchor) ***
'********************************
'returns coordinates of n where a grid is defined with
'
'n: given in grid-units
'grid: distance between two gridlines
'anchor: coordinates of the 0-position of the grid
'x,y: coordinate of a-system
'============================
'b'
DEF gridcoord(n,grid,anchor)
n=INT(n)
gridcoord=anchor+grid*n
END DEF 'of gridcoord(n,grid,anchor)
'c'============================
'********************************
'*** gridpos_f(a,grid,anchor) ***
'********************************
'returns 'floor-rounded' position of a point in 'gridunits'
'where grid is the distance between two gridlines given in normal coordinates
'anchor is the 0-position of the grid in normal coordinates
'============================
'b'
DEF gridpos_f(a,grid,anchor)
RETURN FLOOR((a-anchor)/grid)
END DEF 'of gridpos_f(a,grid,anchor)
'c'============================
'============
'returns the number of data separated by separator$
'";" will be counted as 2 (";" is separator)
'"asd" will be counted as 1 (";" is separator)
DEF lensepstr(string$,separator$)
RETURN count_instr(string$,separator$)+1
END DEF
'============
'returns a substring within a given string$(s1$ or s2$) with (s1$ or s2$) as separator and thus dividing the string in sections
DEF insepstr$(section,s1$,S2$)
IF MAX(LEN(s1$),LEN(s2$))=LEN(s1$) THEN 's1 the longest?
separator$=s2$ ! string$=s1$ 'shortest is separator
ELSE
string$=s2$ ! separator$=s1$
ENDIF
IF string$="" THEN RETURN "ERROR" '-1 problematisch bei der auswertung. Stoppzeichen definieren und übergeben?
'insepstr$(2,",","123,4567,890") -> 4567
option_base_=OPTION_BASE()
OPTION BASE 1
length=LEN(string$)
IF INSTR(string$,separator$,1)=-1 AND section=1 THEN
OPTION BASE option_base_
RETURN string$ '-1 'trennzeichen nicht vorhanden
ENDIF
pos2=0
FOR n= 1 TO section
pos1=pos2+1
IF pos1<=LEN(string$) THEN
pos2=INSTR(string$,separator$,pos1)
ELSE
OPTION BASE option_base_
RETURN "ERROR" '-1
ENDIF
IF pos2 = -1 THEN BREAK 'letztes komma fehlt
NEXT n
IF n=section AND pos1<=length THEN pos2=length+1 'letzte komma fehlt
IF n<section THEN
OPTION BASE option_base_
RETURN "ERROR" '-1 'weniger sections als erwartet
ENDIF
'(n=section und noch zeichen übrig: letztes komma fehlt, sonst zuwenig sections
result$=MID$(string$,pos1,pos2-pos1)
OPTION BASE option_base_
RETURN result$
END DEF 'of insepstr$(,,)
'============
'counts the occurrances of a sub$ within a string$
'"xx" in "xxxx" will be counted as 2
DEF count_instr(string$,SUB$)
_base_=OPTION_BASE()
result=INSTR(string$,SUB$)
IF result=-1 THEN RETURN 0
IF result=LEN(string$)-LEN(SUB$)+_base_ THEN RETURN 1
RETURN 1+ count_instr(MID$(string$,result+LEN(SUB$)),SUB$)
END DEF
'===========
'y'
OPTION TEXT POS CENTRAL
'use inputfield(keyb-design$,separator$) to design a keyboard. keyb-design$ contains layout/single keys of keyboard, separator$ is the character used for separation
'each row contains two equal number of keys/characters, where the first entry corresponds to the normal layout, the second, separated by separator$,
'corresponds to the layout activated by caps-lock (here:∆ used for toggeling between normal and caps-layout)
'the next row is separated by separator$
'long keys can be defined as doubled, trippled etc. keys. the length corresponds to the number of equal keys
'use inputfield_create(x-pos,y,pos,caps-status) to depict the keyboard on the screen. caps-status1: normal keyboard, 2:caps-keyboard
'use inputfield_identify$(x,y,caps-status) to attribute touch to a character connected to the touch-area
'inputfield("12121212121.12121212121",".")
'inputfield("111111.111111.222222.222222.333333.333333",".")
'inputfield("111222333.AAABBBCCC.444555666.DDDEEEFFF",".")
inputfield("0123+¶0ABC+¶456-¶DEF-¶789*¶123*¶ABC/¶456/¶DEF.¶789,¶∆∆∆∆¶∆∆∆∆","¶")
'inputfield("123+I123+I456-I456-I789*I789*I,0./I I ","I")
'inputfield("qweØQWEØasdØASD","Ø") 'create keyboard-layout
inputfield("^1234567890ß`Ø°!§$%&/()=?´Øqwertzuiopü+¬¬ØQWERTZUIOPÜ*¬¬Øasdfghjklöä#≥ØASDFGHJKLÖÄ'≤Ø<yxcvbnm,.-∆∆∆Ø>YXCVBNM;:_∆∆∆Ø Ø ","Ø")
FIELD "output" TEXT "" AT SCREEN_WIDTH()*.1,SCREEN_HEIGHT()*.9 SIZE SCREEN_WIDTH()*.9,SCREEN_HEIGHT()*.1 RO 'output field
caps=1
main_loop3:
GRAPHICS
GRAPHICS CLEAR
REFRESH OFF
inputfield_create(SCREEN_WIDTH()*0,10,caps) 'create graphics
REFRESH ON
main_loop1:
key_last_pressed$=inputfield_identify$(caps) 'get key
IF key_last_pressed$="∆" THEN
caps=1-(caps-1)+1
GOTO main_loop3
ENDIF
keypressed$=keypressed$&key_last_pressed$
FIELD "output" TEXT keypressed$ 'show key pressed
GOTO main_loop1