Scrollable message logbook
Posted: Sat Feb 16, 2019 12:54 pm
In (old time) text oriented games like Hamurabi and Eliza, textual (and embedded numeric) information is passed to the user at each iteration.
It is handy to have a message window where new information is added to the bottom of the window, while pushing up the earlier messages. A sB LIST is used to display the messages and retain the history with an user specified capacity. The message list in the window is scrollable.
Three functions are provided-
msg() - the user has to define the window and list in the yellow area
put_msg(a$) - adds message a$ to the logbook and displays it
c_list(....) - low level function, not for the user
The user is responsible for formatting the messages such that they fit in the specified width of the message window.
The message window is meant to be permanent on the screen. However, it may be removed by HIDING the list and do a GRAPHICS CLEAR over the window. Each put_msg() call will restore the message window.
It is handy to have a message window where new information is added to the bottom of the window, while pushing up the earlier messages. A sB LIST is used to display the messages and retain the history with an user specified capacity. The message list in the window is scrollable.
Three functions are provided-
msg() - the user has to define the window and list in the yellow area
put_msg(a$) - adds message a$ to the logbook and displays it
c_list(....) - low level function, not for the user
The user is responsible for formatting the messages such that they fit in the specified width of the message window.
The message window is meant to be permanent on the screen. However, it may be removed by HIDING the list and do a GRAPHICS CLEAR over the window. Each put_msg() call will restore the message window.
Code: Select all
' Demo of scrollable message logbook
'
graphics ! graphics clear .8,.8,.8 ! draw color 0,0,0
button "stop" text "Stop" at 600,900 size 60,30
msg() ' *** initialize the message window
for i=1 to 195 ! put_msg(nonsense$()) ! next i ' *** fill table fast
do
put_msg(nonsense$()) ' generate and add a (nonsense) message
pause rnd(1)
if rnd(1)<.2 then pause 6 ' long pause to enable list scrolling
until button_pressed("stop")
end
def msg() ' *** define name, position, size of the message window
'y'
nmax=200 ' max # of kept messages in the (FIFO) table
dim txt$(nmax+1) ' table with messages
n$ ="msg" ' name (handle) of the list
t$ ="Messages" ' title of the list
x =300 ' x position of the left upper window corner
y =200 ' y position
w =400 ' width
h =500 ' height (determines the # of displayed messages)
end def
''
def put_msg(a$)
pt+=1 ! if pt>msg.nmax then pt=1 ! m+=1 ! msg.txt$(pt)=m & " " & a$
c_list(msg.n$,msg.t$,msg.txt$,msg.nmax,pt,msg.x,msg.y,msg.w,msg.h)
' list msg.n$ show In case that the list is temporarily hidden
end def
' id$ = object name
' cont$ = array met elementen
' size = aantal elementen in de list
' pt = current pointer
'
def c_list(id$,title$,cont$(),size,pt,xt,yt,w,h)
if pt=size then full=1
if full then dm=size+1 else dm=pt+1
dim temp$(dm)
k=0
if full then
for i=pt+1 to size ! k+=1 ! temp$(k)=cont$(i) ! next i
end if
for i=1 to pt ! k+=1 ! temp$(k)=cont$(i) ! next i
list id$ text temp$ at xt+2,yt+32 size w-4,h-34
list id$ select k
draw size 3
draw rect xt,yt to xt+w,yt+h ! draw line xt,yt+30 to xt+w,yt+30
draw color 0,0,1
draw text title$ at (2*xt+w-text_width(title$))/2,yt+5
end def
def nonsense$() ' **** used for the demo only
a$="abcd efgh ijklm nopq rstu vwx yz " ! la=len(a$) ! b$=""
for nc=1 to 30+rnd(11) ! b$&=mid$(a$,rnd(la),1) ! next nc
return b$
end def