Library Function:
"TextEx" |
remaining_text$ = TextEx(text$, justify, win_x, win_y,
width, height, char_spacing, line_spacing)
The "TextEx" function is an extension of the Yabasic
Text function which can place a big string in a custom text-area field. If there
is more text than there is space, the remaining text is returned by the
function.
For an example of how this function can be used see the
illustrated example code at the bottom of this page.
| Parameter |
Description |
| text$ |
String. The text
which is to be placed by the TextEx function. |
| justify |
0 - do not justify
text
1 - justify text |
| win_x |
x-coordinate of the
top-left corner of the text-area |
| win_y |
y-coordinate of the
top-left corner of the text-area |
| width |
width of the
text-area |
| height |
height of the
text-area |
| char_spacing |
How many (x) pixels
to use for each character in the text. Use 10 for the (default)
character-spacing that the standard text function uses.
Note that when justify is on, then this is used as an
indication, and is then adapted to justify the text. That means this
setting still has an influence even when justify is on. |
| line_spacing |
How many (y) pixels
to use for each line of text. Use 15 for a fairly default
line-spacing. |
sub TextEx$(text$, justify, win_x, win_y, width, height, char_spacing, line_spacing)
ch_p_line = width/char_spacing
avail_lines = int(height / line_spacing)+1
l = 1
while(len(text$)>ch_p_line and avail_lines > l)
sp_index = ch_p_line
c$ = mid$(text$,sp_index,1)
if c$ <> " " and c$ <> "-" then
while(c$ <> " " and c$ <> "-")
c$=mid$(text$,sp_index,1)
sp_index = sp_index -1
wend
else
sp_index = sp_index - 1
endif
line$ = mid$(text$,0,sp_index+1)
if justify = 1 then
j_char_spacing = width / len(line$)
j_char_spacing = j_char_spacing + ((j_char_spacing - 10) / len(line$))
else
j_char_spacing = char_spacing
endif
for c=1 to len(line$)
text (c-1)*j_char_spacing+win_x,l*line_spacing + win_y, mid$(text$,c,1)
next c
text$=mid$(text$,len(line$)+2,len(text$)-len(line$)+2)
l = l + 1
wend
if l = avail_lines then
return text$
else
for c = 1 to ch_p_line
text (c-1)*char_spacing + win_x, l*line_spacing + win_y,mid$(text$,c,1)
next c
endif
end sub |
Example Code
Displays a page-like box with shading and uses the TextEx$
function to display a big string over several pages. Tip - don't type the whole
test$ but type one line and repeat that line to save yourself some typing, or
just type any sizable string of your own liking. Just make sure it's at least
about as long as the one below, or you won't be able to see the page-flipping
that this example features.
scr_width = 300
scr_height = 300
l_margin = 30
r_margin = 20
t_margin = 20
b_margin = 20
width = scr_width - l_margin - r_margin
height = scr_height - t_margin - b_margin
test$="This is a long textstring to test out various text positioning algorithms that you can use to help your program look a lot better than you're used to ... This is a long textstring to test out various text positioning algorithms that you can use to help your program look a lot better than you're used to ... This is a long textstring to test out various text positioning algorithms that you can use to help your program look a lot better than you're used to ... This is a long textstring to test out various text positioning algorithms that you can use to help your program look a lot better than you're used to ... "
open window 640, 512
p_count = 1
while(len(test$)>0)
setdrawbuf 1
setdispbuf 0
setrgb 0,0,0,0
clear window
setrgb 1,255,255,255
setrgb 2,255,255,255
setrgb 3,155,155,155
fill rectangle win_x,win_y,win_x+scr_width,win_y+scr_height
gtriangle win_x,win_y to win_x,win_y + scr_height to win_x + scr_width,win_y
setrgb 1,155,155,155
gtriangle win_x + scr_width, win_y to win_x,win_y + scr_height to win_x + scr_width,win_y + scr_height
setrgb 1,50,0,0
test$ = TextEx$(test$,1,win_x + l_margin,win_y+r_margin,width,height,8,15)
pagenr$ = "Page " + str$(p_count)
setrgb 1,255,255,255
text win_x + scr_width - (len(pagenr$) * 10), win_y + scr_height + 20,pagenr$
setdispbuf 1
inkey$
p_count = p_count + 1
wend
inkey$ |
(c) 2001 Arwin van Arum
"Sony" and "Playstation 2" are registered trademarks owned by Sony Inc.
|