! This program is designed to demonstrate
! the gr.touch and gr.bitmap, commands in
! the context of a graphics application.
!
! Run the program and follow the instructions.
!
! Note: You can not exercise all the features
! of this program if you do not have a physical
! keyboard.


!load library/setup library
INCLUDE DonsBasicLibrary.bas
INCLUDE F11Keyboard.bas
!Add functions here.
!setup display/keyboard
L_LibrarySetup(1,0,1,0,0)
L_addscreen(64,16,3)
!Add graphics here.
L_keyboardsetup(225,5)
L_hidescreen(0)
!switch to screen 1
L_changescreen(1)

!instructions
L_setcolors(1,3)
L_clear()
L_locate(11,1):L_write("F11_graphics_touch with Don's Basic Library")
L_locate(1,3):L_write("Same great sample program, now with an on-screen keyboard!")
L_locate(1,5):L_write("Instructions:")
L_locate(1,6):L_write("  Touch the screen. A small star will appear.")
L_locate(1,7):L_write("  Pressing UP makes the next star bigger.")
L_locate(1,8):L_write("  Pressing DOWN makes the next star smaller.")
L_locate(1,9):L_write("  Pressing GO toggles between the star and a galaxy bitmap.")
L_locate(1,11):L_write("  When ready, Tap the screen.")
L_locate(1,12):L_write("  When done, Press the EXIT key.")
! Wait for the screen to be tapped
GOSUB gettouch

L_hidescreen(1)
L_showkeyboard(1)

Start:
! open the Graphics Screen with a
! white background

!GR.OPEN 255, 0,0,0

! Load the bitmap object and set mode to dots

GR.BITMAP.LOAD BM_ptr, "Galaxy.png"
m = 1

! Set the color of the dot to filled Black

GR.COLOR 255,255,255,255,1

! Set the start radius to 1
r = 1

! Run an infinite loop testing for a touch
! and looking for key presses

touch=0
stp=0
DO
 DO 
  GR.TOUCH touch, x , y
 UNTIL touch

 keytouch=0
 L_whatkey(x,y)
 GOSUB getlastkey
 !retreives type$, and keytouch
 !as long as type$ is a zero, keytouch is the key number from the buttonlist.
 !if keytouch = 0 then no key
 if keytouch>0 then pause 500
 IF keytouch=1
  !go
  key$="go"
  IF m = 1 THEN m = 2	ELSE  m = 1
 ENDIF
 IF keytouch=2
  !up
  key$="up"
  r = r + 1
 ENDIF
 IF keytouch=3
  !down
  key$="down"
  r = r - 1
 ENDIF
 IF keytouch=4
  !exit
  stp=1
 ENDIF
 if keytouch=0
  IF m = 1 THEN GR.CIRCLE n, x, y, r ELSE GR.BITMAP.DRAW n, BM_ptr , x, y
  GR.RENDER
 endif
UNTIL stp=1

!This last stuff isn't needed.
! When you exit the graphic screen
! with the back key, you will get
! run time error at gr.touch. This
! This because the graphics mode
! is turned off when the graphics
! screen is  exited. Hit the Back
! key one more time to get back
! to the Editor.

! The Onerror will catch the error
! and not print the graphics not
! opened error message
!ONERROR:
END
