add tab bar, for when we need it

This commit is contained in:
Nico 2021-03-30 14:29:34 +01:00
parent 80f8b9bdd1
commit 2c4adeeb00
1 changed files with 26 additions and 1 deletions

27
main.fs
View File

@ -53,6 +53,9 @@ variable count-messages-shown
\ the rest are TBA
variable screen
0 screen !
\ variable screens contains the highest unlocked screen number.
variable screens
0 screens !
\ message contains a string message which is printed on the screen.
\ because forth is weird, strings can be stored in variables but it's easier to just store them someplace else and then store that address and the string's length in the variable (this is what S" " does and what "type" expects)
create message 0 , 0 , 0 ,
@ -197,6 +200,8 @@ S" you feel like throwing some stuff into the pool." set-message
\ inc-y increments the y coordinate being drawn at.
: inc-y 1 + ;
\ inc-x increments the x coordinate being drawn at.
: inc-x swap 1 + swap ;
\ print-rate prints the current device output rate on the screen.
: print-rate
@ -204,6 +209,26 @@ S" you feel like throwing some stuff into the pool." set-message
\ first convert to floating point, divide by 1000 to get seconds from milliseconds, then do 1/n to get the devices/second from seconds/device
." (" devices/tick 1000e f* f. ." devices/second)" ;
: draw-screen-name ( i -- )
case
0 of ." Devices " endof
1 of ." Garden " endof
endcase ;
\ draw-tab-bar draws the tab bar. TODO make this into smaller words
: draw-tab-bar ( x y -- )
2dup at-xy
screens @ if \ 0 is false in forth, so if the number of screens is zero, don't draw the bar.
screens @ 1+ 0 do
i dup
screen @ = if
." >" bl
drop
then
draw-screen-name
loop inc-y
then ;
\ draw-message draws the stored message on the screen.
: draw-message ( x y -- x y )
2dup at-xy
@ -264,7 +289,7 @@ S" you feel like throwing some stuff into the pool." set-message
\ : draw-screen clear-all ;
\ main game loop
: game-loop begin wait-tick game-tick handle-input 1 1 draw-devices-screen 0 until ;
: game-loop begin wait-tick game-tick handle-input 1 1 draw-tab-bar draw-blank draw-devices-screen 0 until ;
\ for use in the debugging shell
: restart page game-loop ;