Menu question

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
GarryRicketson
Veteran
Posts: 90
Joined: Fri Jul 16, 2010 10:02 am
Location: Cuencame,Durango,Mexico
Contact:

Menu question

Post by GarryRicketson »

Maybe you guys can help me with this,it was the start of a menu,:

Code: Select all

  REM
DEFINT A-Z

MenuBackground& = _LOADIMAGE("smallroad.png", 32)
MainMenu& = _NEWIMAGE(640, 480, 32)
SCREEN MainMenu&

'--------------------- FONT ---------------------------------------
TTfont$ = "timesbd"
height& = 32
style$ = ""
fnt& = _LOADFONT(TTfont$ + ".ttf", height&, style$)
IF fnt& = 0 THEN BEEP
_FONT fnt&


DIM SHARED mx%, my%, mbl%, mbm%, mbr%
DIM SHARED OOption%

GOSUB MakBoxes
GOSUB MakLabels
_MOUSESHOW

DO
    _LIMIT 30
    a$ = INKEY$
    _PUTIMAGE , MenuBackground&, MainMenu&
    MousePoll
    COLOR _RGB32(255, 255, 255)
    LOCATE 1, 1
    PRINT mx%, my%, mbl%, mbm%, mbr%
    GOSUB MakBoxes
    GOSUB MakLabels
    GOSUB MenuOption
    IF mbl% = -1 THEN
        IF OOption% <> 0 THEN
            GOSUB OtherPrograms
        END IF
    END IF
    _DISPLAY
LOOP UNTIL _KEYDOWN(27)
SLEEP
SYSTEM

'------------------------- Gosubs  -----------------------------------------------------------------
OtherPrograms:
SELECT CASE OOption%
    CASE 1
        CLS
        COLOR _RGB32(255, 0, 255)
        _PRINTMODE _KEEPBACKGROUND
        _PRINTSTRING (220, 100), "Animal Sounds", MainMenu&
        _DISPLAY
        DO: LOOP UNTIL _KEYDOWN(32)
        OOption% = 0
        a$ = INKEY$
        WHILE a$ <> "": a$ = INKEY$: WEND
    CASE 2
        CLS
        COLOR _RGB32(255, 255, 0)
        _PRINTMODE _KEEPBACKGROUND
        _PRINTSTRING (220, 100), "Lets Paint", MainMenu&
        _DISPLAY
        DO: LOOP UNTIL _KEYDOWN(32)
        OOption% = 0
        a$ = INKEY$
        WHILE a$ <> "": a$ = INKEY$: WEND
    CASE 3
        CLS
        COLOR _RGB32(0, 255, 255)
        _PRINTMODE _KEEPBACKGROUND
        _PRINTSTRING (220, 100), "Letter Sounds", MainMenu&
        _AUTODISPLAY
        DO: LOOP UNTIL _KEYDOWN(32)
        OOption% = 0
        a$ = INKEY$
        WHILE a$ <> "": a$ = INKEY$: WEND
    CASE 4
        CLS
        COLOR _RGB32(255, 255, 255)
        _PRINTMODE _KEEPBACKGROUND
        _PRINTSTRING (220, 100), "QUIT", MainMenu&
        _AUTODISPLAY
        DO: LOOP UNTIL _KEYDOWN(32)
        OOption% = 0
        a$ = INKEY$
        WHILE a$ <> "": a$ = INKEY$: WEND
END SELECT
RETURN

MenuOption:
'check for hover
IF mx% > 120 AND mx% < 520 THEN
    SELECT CASE my%
        CASE 100 TO 131
            LINE (120, 100)-(520, 131), _RGB32(255, 255, 0), BF
            COLOR _RGB32(0, 0, 0)
            _PRINTMODE _KEEPBACKGROUND
            _PRINTSTRING (220, 100), "Animal Sounds", MainMenu&
            OOption% = 1
        CASE 163 TO 194
            LINE (120, 164)-(520, 195), _RGB32(255, 255, 0), BF
            COLOR _RGB32(0, 0, 0)
            _PRINTMODE _KEEPBACKGROUND
            _PRINTSTRING (220, 164), "Lets Paint", MainMenu&
            OOption% = 2

        CASE 226 TO 257
            LINE (120, 228)-(520, 259), _RGB32(255, 255, 0), BF
            COLOR _RGB32(0, 0, 0)
            _PRINTMODE _KEEPBACKGROUND
            _PRINTSTRING (220, 228), "Letter Sounds", MainMenu&
            OOption% = 3
        CASE 289 TO 320
            LINE (120, 292)-(520, 323), _RGB32(255, 255, 0), BF
            OOption% = 1
            COLOR _RGB32(0, 0, 0)
            _PRINTMODE _KEEPBACKGROUND
            _PRINTSTRING (220, 292), "QUIT", MainMenu&
            OOption% = 4
        CASE ELSE
            OOption% = 0
            GOSUB MakBoxes
            GOSUB MakLabels
    END SELECT
ELSE
    OOption% = 0
END IF
RETURN


MakBoxes:
x1 = 120: y1 = 100
FOR t = 1 TO 4
    LINE (x1, y1)-(x1 + 400, y1 + 31), _RGB32(211, 211, 211), BF
    y1 = y1 + 64
NEXT t
RETURN

MakLabels:
COLOR _RGB32(0, 0, 0)
_PRINTMODE _KEEPBACKGROUND
_PRINTSTRING (220, 100), "Animal Sounds", MainMenu&
_PRINTSTRING (220, 164), "Lets Paint", MainMenu&
_PRINTSTRING (220, 228), "Letter Sounds", MainMenu&
_PRINTSTRING (220, 292), "QUIT", MainMenu&
RETURN

'------------------------- Call Subs ---------------------------------------------------------------
SUB MousePoll ()
DO WHILE _MOUSEINPUT
    mx% = __MOUSEX: my% = _MOUSEY: mbl% = _MOUSEBUTTON(1): mbr% = _MOUSEBUTTON(2): mbm% = _MOUSEBUTTON(3)
LOOP
END SUB
  
the image is attached,
Ok, now I think if we just do it this way, rather then also posting eache program that the menu is supposed to run,
this would be the "Animal sounds" file name: animalsounds.bas , or a sub name ? "animalsounds",

Code: Select all

PRINT "This is the animal sounds program"
PLAY "abcde"
PRINT "END OF PROGRAM" 
END '///or return, I am not sure how to do that , so it would go back to the main menu when the user quits
I think, if I see, how it works or needs to be, so it runs, this simple code, as "animalsounds" then I can also use the same, to run the real programs,..I suppose each one will be in a SUB, or the could be compiled, and shell to them, not sure about the best way to do that,..
If anyone can help on this, it would be greatly appreciated,..
thanks from Garry
Attachments
smallroad.png
smallroad.png (133.87 KiB) Viewed 13781 times
Post Reply