Switching between screens is actually easy. Maintain a variable that keeps track which screen is currently being displayed. While switching to a new screen, always update this variable. Use the variable to determine which set of Menucheck tests should be run for a particular screen. Subroutines are very useful for compartmentalizing the code.
Here is an example CUBLOC BASIC listing, and an include file from CuCanvas with the menu creation commands:
CT1721treemenu.cub
- Code: Select all
Const Device = CT1720
Ramclear
Set Pad 0,4,5
On Pad Gosub ProcessTouch
Dim TX1 As Integer
Dim TY1 As Integer
Dim CurrentScreen As Byte
#define _MAINMENU 0
#define _SUBMENU1 1
#define _SUBMENU2 2
#define _SUBMENU3 3
#define _SUBMENU4 4
MAIN
CurrentScreen = _MAINMENU
Do
If CurrentScreen = _MAINMENU Then
Set Onpad Off
DisplayTime
Set Onpad On
Endif
Delay 250
Loop
ProcessTouch:
TX1 = GetpadX()
TY1 = GetpadY()
Select Case CurrentScreen
Case _MAINMENU
ProcessMainMenu
Case _SUBMENU1
ProcessSubMenu1
Case _SUBMENU2
ProcessSubMenu2
Case _SUBMENU3
ProcessSubMenu3
Case _SUBMENU4
ProcessSubMenu4
End Select
Return
End
Sub ProcessMainMenu()
If Menucheck(0,TX1,TY1) = 1 Then
FlashMenu 0
CurrentScreen = _SUBMENU1
Cls
SUBMENU1
Elseif Menucheck(1,TX1,TY1) = 1 Then
FlashMenu 1
CurrentScreen = _SUBMENU2
Cls
SUBMENU2
Elseif Menucheck(2,TX1,TY1) = 1 Then
FlashMenu 2
CurrentScreen = _SUBMENU3
Cls
SUBMENU3
Elseif Menucheck(3,TX1,TY1) = 1 Then
FlashMenu 3
CurrentScreen = _SUBMENU4
Cls
SUBMENU4
Endif
End Sub
Sub ProcessSubMenu1()
If Menucheck(0,TX1,TY1) = 1 Then
FlashMenu 0
Beeper 1
Elseif Menucheck(1,TX1,TY1) = 1 Then
FlashMenu 1
CurrentScreen = _MAINMENU
Cls
MAIN
Endif
End Sub
Sub ProcessSubMenu2()
If Menucheck(0,TX1,TY1) = 1 Then
FlashMenu 0
Beeper 2
Elseif Menucheck(1,TX1,TY1) = 1 Then
FlashMenu 1
CurrentScreen = _MAINMENU
Cls
MAIN
Endif
End Sub
Sub ProcessSubMenu3()
If Menucheck(0,TX1,TY1) = 1 Then
FlashMenu 0
Beeper 3
Elseif Menucheck(1,TX1,TY1) = 1 Then
FlashMenu 1
CurrentScreen = _MAINMENU
Cls
MAIN
Endif
End Sub
Sub ProcessSubMenu4()
If Menucheck(0,TX1,TY1) = 1 Then
FlashMenu 0
Beeper 4
Elseif Menucheck(1,TX1,TY1) = 1 Then
FlashMenu 1
CurrentScreen = _MAINMENU
Cls
MAIN
Endif
End Sub
Sub Beeper(Num As Byte)
Dim i As Byte
For i = 1 To Num
High 18
Delay 100
Low 18
Delay 200
Next
End Sub
Sub FlashMenu(Num As Byte)
Menureverse Num
Delay 150
Menureverse Num
End Sub
Sub DisplayTime()
Glocate 16,220
Font 0,0
Dprint Dp(Bcd2bin(Time(2)),2,1),":",Dp(Bcd2bin(Time(1)),2,1),":",Dp(Bcd2bin(Time(0)),2,1)
End Sub
#include "CT1721treemenu.inc"
CT1721treemenu.inc
- Code: Select all
SUB MAIN()
FONT 6,1
STYLE 0,0,0
GLOCATE 96,24
GPRINT "Main Menu"
FONT 0,1
MENUSET 0,2,40,96,144,128
MENUTITLE 0,20,8,"Submenu 1"
MENUSET 1,2,168,96,280,128
MENUTITLE 1,24,8,"Submenu 2"
MENUSET 2,2,40,152,144,184
MENUTITLE 2,20,8,"Submenu 3"
MENUSET 3,2,168,152,280,184
MENUTITLE 3,24,8,"Submenu 4"
LINESTYLE 0
DOTSIZE 0,0
COLOR 1
BOX 80,16,232,56
FONT 4,0
END SUB
SUB SUBMENU1()
FONT 6,1
STYLE 0,0,0
GLOCATE 96,24
GPRINT "Submenu 1"
LINESTYLE 0
DOTSIZE 0,0
COLOR 1
BOX 80,16,232,56
FONT 2,1
MENUSET 0,2,88,88,224,120
MENUTITLE 0,22,8,"Beep 1 time"
MENUSET 1,2,0,208,72,239
MENUTITLE 1,10,7,"<BACK"
FONT 4,0
END SUB
SUB SUBMENU2()
FONT 6,1
STYLE 0,0,0
GLOCATE 96,24
GPRINT "Submenu 2"
LINESTYLE 0
DOTSIZE 0,0
COLOR 1
BOX 80,16,232,56
FONT 2,1
MENUSET 0,2,88,88,224,120
MENUTITLE 0,16,8,"Beep 2 times"
MENUSET 1,2,0,208,72,239
MENUTITLE 1,10,7,"<BACK"
FONT 4,0
END SUB
SUB SUBMENU3()
FONT 6,1
STYLE 0,0,0
GLOCATE 96,24
GPRINT "Submenu 3"
LINESTYLE 0
DOTSIZE 0,0
COLOR 1
BOX 80,16,232,56
FONT 2,1
MENUSET 0,2,88,88,224,120
MENUTITLE 0,16,8,"Beep 3 times"
MENUSET 1,2,0,208,72,239
MENUTITLE 1,10,7,"<BACK"
FONT 4,0
END SUB
SUB SUBMENU4()
FONT 6,1
STYLE 0,0,0
GLOCATE 96,24
GPRINT "Submenu 4"
LINESTYLE 0
DOTSIZE 0,0
COLOR 1
BOX 80,16,232,56
FONT 2,1
MENUSET 0,2,88,88,224,120
MENUTITLE 0,16,8,"Beep 4 times"
MENUSET 1,2,0,208,72,239
MENUTITLE 1,10,7,"<BACK"
FONT 4,0
END SUB