Scalable List
#1
An example for the Discord channel.  This isn't set up with a very intuitive interface, as I cobbled it together in all of about 10 minutes quick work.  I doubt anyone will learn anything from this, without popping into discord and actually chatting with me in person so I can help walk through what we're doing and why in a life-time session.  It's just easier to share code of this length here, than it is there, but it's easier there to actually discuss it in real time so I can answer questions and such as we go.  My apologies to anyone who finds this confusing or a waste of time.  ;D 


Code: (Select All)
Screen _NewImage(640, 640, 32)
$Color:32

ReDim Shared lists(5, 5, 0) As String * 10 'make a resizable list array
Dim Shared As Integer list2use, listcount 'track which list we're using, and how many we have

addDefaultLabels

Do
    Cls
    m = MBS 'mousebutton status
    If m And 8 Then 'left mouse button clicked
        X = (_MouseX - 4) \ 127: Y = (_MouseY - 4) \ 127 'in which box was the mouse butoon pressed?
        If Y = 4 Then 'we're on the last row, which is always going to be my command row
            Select Case X
                Case 0 'home
                    list2use = 0
                    editMode = 0
                Case 1 'edit item
                    editMode = -1
                Case 2 'next list
                    list2use = list2use + 1
                    If list2use > listcount Then list2use = 0
                    editMode = 0
                Case 3 'delete list
                    'not functional for this demo.  LOL!  I'm just trying to keep things simple..ish.
                Case 4 'add list
                    ReformLists
                    listcount = listcount + 1
                    list2use = listcount
                    addDefaultLabels
                    editMode = 0
            End Select
        Else
            If editMode Then
                Color White, Red
                Locate 1, 1: Input "Enter the name for the item you clicked on: "; temp$
                lists(X, Y, list2use) = temp$
                Color White, Black
                editMode = 0
            Else
                Color White, Red
                Locate 1, 1: Print "You clicked on: "; lists(X, Y, list2use)
                Print "Which was item "; X; ","; Y; "in list"; list2use
                Color White, Black
                _Display
                Sleep
            End If
        End If
    End If
    _Limit 30
    DrawBoxes list2use
    _Display
Loop Until _KeyDown(27)

Sleep

Sub ReformLists
    Dim temp(10, 10, listcount + 1) As String * 10
    For z = 0 To listcount
        For x = 0 To 4
            For y = 0 To 4
                temp(x, y, z) = lists(x, y, z) 'make a copy of the old data
    Next y, x, z
    ReDim lists(x, y, listcount + 1) As String * 10 'notice we're making our lists array larger to hold the new information?
    For z = 0 To listcount
        For x = 0 To 4
            For y = 0 To 4
                lists(x, y, z) = temp(x, y, z) 'copy the old data back over
    Next y, x, z
    'We have to do things this way as REDIM _PRESERVE doesn't work across multi-dimensional arrays
End Sub

Sub addDefaultLabels
    lists(4, 4, list2use) = "Add List"
    lists(3, 4, list2use) = "Delete List"
    lists(2, 4, list2use) = "Next List"
    lists(1, 4, list2use) = "Edit Item"
    lists(0, 4, list2use) = "Return Home"
End Sub



Sub DrawBoxes (list2use)
    For x = 0 To 4
        For y = 0 To 4
            Line (x * 127 + 4, y * 127 + 4)-Step(120, 120), White, B
            _PrintString (x * 127 + 20, y * 127 + 60), lists(x, y, list2use)
        Next
    Next
End Sub


Function MBS% 'Mouse Button Status
    Static StartTimer As _Float
    Static ButtonDown As Integer
    Static ClickCount As Integer
    Const ClickLimit## = 0.2 'Less than 1/4th of a second to down, up a key to count as a CLICK.
    '                          Down longer counts as a HOLD event.
    Shared Mouse_StartX, Mouse_StartY, Mouse_EndX, Mouse_EndY
    While _MouseInput 'Remark out this block, if mouse main input/clear is going to be handled manually in main program.
        Select Case Sgn(_MouseWheel)
            Case 1: tempMBS = tempMBS Or 512
            Case -1: tempMBS = tempMBS Or 1024
        End Select
    Wend


    If _MouseButton(1) Then tempMBS = tempMBS Or 1
    If _MouseButton(2) Then tempMBS = tempMBS Or 2
    If _MouseButton(3) Then tempMBS = tempMBS Or 4


    If StartTimer = 0 Then
        If _MouseButton(1) Then 'If a button is pressed, start the timer to see what it does (click or hold)
            ButtonDown = 1: StartTimer = Timer(0.01)
            Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
        ElseIf _MouseButton(2) Then
            ButtonDown = 2: StartTimer = Timer(0.01)
            Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
        ElseIf _MouseButton(3) Then
            ButtonDown = 3: StartTimer = Timer(0.01)
            Mouse_StartX = _MouseX: Mouse_StartY = _MouseY
        End If
    Else
        BD = ButtonDown Mod 3
        If BD = 0 Then BD = 3
        If Timer(0.01) - StartTimer <= ClickLimit Then 'Button was down, then up, within time limit.  It's a click
            If _MouseButton(BD) = 0 Then tempMBS = 4 * 2 ^ ButtonDown: ButtonDown = 0: StartTimer = 0
        Else
            If _MouseButton(BD) = 0 Then 'hold event has now ended
                tempMBS = 0: ButtonDown = 0: StartTimer = 0
                Mouse_EndX = _MouseX: Mouse_EndY = _MouseY
            Else 'We've now started the hold event
                tempMBS = tempMBS Or 32 * 2 ^ ButtonDown
            End If
        End If
    End If
    MBS = tempMBS
End Function
Reply
#2
"Return Home" = 11 characters...
it is better  REDIM lists(5,5,0) as  string  * 11, isn't it?

Hi Steve
I was  just kidding....

Do you can post an help for user?
I never got a list in a box, I can click on a box and get the right position box as feedback, I never was able to enter Edit mode

What must I expect from it?
Reply
#3
(08-13-2022, 10:25 AM)TempodiBasic Wrote: "Return Home" = 11 characters...
it is better  REDIM lists(5,5,0) as  string  * 11, isn't it?

It probably would have just been better to call it a plain "Home" button, but it's still functional even if it's leaving an E dangling.  Wink
Reply




Users browsing this thread: 4 Guest(s)