Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to create a simple menu
#8
Is what I'm trying to do here just too janky or something?  This is the latest iteration, and logically, it should display a screen of randomly generated lines, then let you open a menu over those lines while they continue to draw.  Instead when you open the menu, the lines stop drawing, and the menu can't be seen.  Maybe I've done something dumb.  I don't know.

Code: (Select All)

''Draw lines and create a menu over it using drawing planes
Option _Explicit
$Color:0

Screen _NewImage(640, 480, 32)
Randomize Timer

''Drawing planes - will be drawn in order to the screen
Dim plane&(1 To 3)
plane&(1) = _NewImage(640, 480, 32) ''lines
plane&(2) = _NewImage(640, 480, 32) ''menu
plane&(3) = _NewImage(640, 480, 32) ''whatever

''main program area
Dim lstate&: lstate& = 1
Dim mstate&: mstate& = 0

Do
    _Limit (60)
    ''test for keypresses
    If _KeyHit > 0 Then
        mstate& = 1
    End If

    ''Draw lines
    RndLines plane&(1)

    ''menu
    If mstate& Then
        PopUpMenu lstate&, mstate&, plane&(2)
    End If

    ''draw all planes to the screen - should work if transparent is 0
    _PutImage , plane&(1), 0
    _PutImage , plane&(2), 0
    _PutImage , plane&(3), 0

    _Display
Loop Until lstate& = 0

_FreeImage plane&(1)
_FreeImage plane&(2)
_FreeImage plane&(3)

System


''----------------------Subroutines--------------------------
Sub PopUpMenu (loopst&, menust&, sbuff&)

    ''routine for popup menu - active subsystems should check for their own input
    Dim mrtxt$(1 To 4)
    mrtxt$(1) = "Resume"
    mrtxt$(2) = "Restart"
    mrtxt$(3) = "Quit"
    mrtxt$(4) = "Get Out"

    Static msel&

    ''Check for input
    If _KeyDown(18432) Then ''up
        msel& = msel& - 1
    End If

    If _KeyDown(20480) Then ''down
        msel& = msel& + 1
    End If
    ''wrap menu cursor
    If msel& < LBound(mrtxt$) Then msel& = UBound(mrtxt$)
    If msel& > UBound(mrtxt$) Then msel& = LBound(mrtxt$)

    If _KeyDown(13) Then ''Enter
        ''Exit the program when enter is pressed on Get Out
        Select Case msel&
            Case 1
                ''close the menu
                menust& = 0: Exit Sub
            Case 2
                ''Restart the drawing
                menust& = 0
                Cls: Exit Sub
            Case 3, 4
                ''quit the program
                loopst& = 0: System
        End Select
    End If

    ''Draw the menu to the screen
    DrawMenuBox 3, 4, mrtxt$(), msel&, sbuff&

    Sleep .001

End Sub ''PopUpMenu


Sub DrawMenuBox (row&, col&, mtxt$(), hl&, sbuff&)

    ''Draw a menu Box on the screen
    Dim tw&, th&, scr&

    ''change the drawing destination
    scr& = _Dest
    _Dest sbuff&

    ''Get the number of lines of text to draw and determine the longest
    th& = UBound(mtxt$) - LBound(mtxt$) + 1

    Dim i
    For i = LBound(mtxt$) To UBound(mtxt$)
        If Len(mtxt$(i)) > tw& Then tw& = Len(mtxt$(i))
    Next

    ''Generate the text Box
    Color Black, White
    ''top row
    Locate row&, col&
    Print "�" + String$(tw&, "�") + "�"

    ''Print txt rows
    For i = 1 To th&
        Locate row& + i, col&
        Print "�" + Space$(tw&) + "�"
    Next

    ''bottom row
    Locate row& + th& + 1, col&
    Print "�" + String$(tw&, "�") + "�"

    ''Print text onto box
    For i = 1 To th&
        If i = hl& Then
            Color White, Black
            Locate row& + i, col& + 1
            Print mtxt$(i) + Space$(tw& - Len(mtxt$(i)))
            Color Black, White
        Else
            Locate row& + i, col& + 1
            Print mtxt$(i) + Space$(tw& - Len(mtxt$(i)))
        End If
    Next

    ''restore color and drawing destination
    Color White, Black
    _Dest scr&

End Sub ''DrawMenuBox


Sub RndLines (sbuff&)

    ''Draw random lines across the screen
    Dim x1&, y1&, x2&, y2&, scr&
    Dim linecolor As _Unsigned Long

    ''Randomize the color
    linecolor = _RGB(Int(Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))

    ''Randomize the line points
    x1& = Int(Rnd * _Width)
    y1& = Int(Rnd * _Height)
    x2& = Int(Rnd * _Width)
    y2& = Int(Rnd * _Height)

    ''Draw the line
    scr& = _Dest
    _Dest sbuff&
    Line (x1&, y1&)-(x2&, y2&), linecolor
    _Dest scr&

End Sub


Here is the executable file in case people can't reproduce my issues.  I'm using Linux Mint 22.1 AMD64.
https://mega.nz/folder/f2RChbrC#hQF0KBiEjmALijWNNWhDGA
Reply


Messages In This Thread
Trying to create a simple menu - by CMR - 05-12-2025, 08:34 PM
RE: Trying to create a simple menu - by Pete - 05-12-2025, 08:48 PM
RE: Trying to create a simple menu - by SMcNeill - 05-12-2025, 09:11 PM
RE: Trying to create a simple menu - by CMR - 05-13-2025, 01:47 AM
RE: Trying to create a simple menu - by bplus - 05-12-2025, 09:05 PM
RE: Trying to create a simple menu - by Pete - 05-12-2025, 09:23 PM
RE: Trying to create a simple menu - by CMR - 05-13-2025, 03:15 AM
RE: Trying to create a simple menu - by CMR - 05-13-2025, 07:00 PM



Users browsing this thread: 2 Guest(s)