Basic Menu System

Applications, examples, and sample programs using products from Comfile Technology

Basic Menu System

Postby Garrett » Wed Mar 17, 2010 2:33 pm

I get a lot of questions about the CUTOUCH from customers, and many of the problems are caused or aggravated by not understanding how to approach setting up a menu system. Switching between several pages and modes seems to give the most trouble. A lot of customers set up endless loops and change the target of On Pad Gosub to point to new locations. Others keep checking the Getpad statements several places in a program. The Getpad coordinates should only ever be accessed ONE time per On Pad interrupt, or you're looking at old coordinates and could accidentally press a button right after reaching a new screen. Lastly some customers try to use new menu button numbers on each screen instead of starting at 0 each time. You can do this, but eventually you'll run out of numbers and that method is extremely hard to modify later.

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
Attachments
CT1721treemenu.inc
(1.5 KiB) Downloaded 979 times
CT1721treemenu.CUb
(2.46 KiB) Downloaded 979 times
CT1721treemenu.cul
(1 Bytes) Downloaded 914 times
User avatar
Garrett
Site Admin
 
Posts: 475
Joined: Tue Nov 07, 2006 1:04 pm
Location: Cubloc HQ

Re: Basic Menu System

Postby Lobobo » Tue Dec 07, 2010 6:01 pm

I cannot believe it's the only example in here... Nobody willing to share "cutouch" experience?
At least big thank you to Garrett.
Lobobo
Terminator
 
Posts: 5
Joined: Mon Nov 22, 2010 6:06 pm

Re: Basic Menu System

Postby sci_prez » Tue Jul 12, 2011 10:56 am

I used this example as the basis for my tree processor application. You can see it on my "Technical Support" posting of Jun 26, 2011.

Tom
sci_prez
SuperDuperDuper
 
Posts: 174
Joined: Tue Mar 10, 2009 6:14 am
Location: eastern Canada


Return to Applications and Examples

Who is online

Users browsing this forum: No registered users and 2 guests

cron