Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What do you guys like to use for mouse mapping?
#16
You guys still have some work to do on being able to set up multiple menus which interact together in a database type format.  Tongue

Code: (Select All)
$Color:32

Const True = -1, False = 0
Const Left = 1, Right = 2, Middle = 3, Center = 3
Const None = 0, Alpha = 1, Numeric = 2, NoCase = 4, Reverse = 8
Const LeftClick = 1, RightClick = 2, LeftDown = 4, RightDown = 8, Hover = 16

Type MenuType
    Valid As _Byte
    Visible As _Byte
    ScrollBarHidden As _Byte
    Top As Integer
    Left As Integer
    Width As Integer
    Height As Integer
    Frame As _Byte
    BorderColor As _Unsigned Long
    BackgroundColor As _Unsigned Long
    Header As _Byte
    Caption As String * 255
    CC As _Unsigned Long 'caption color
    CBG As _Unsigned Long 'caption background color
    HighLightColor As _Unsigned Long
    Exit As _Byte
    Entries As Integer
    TopEntry As Integer
    ListColor As _Unsigned Long
    ListBackground As _Unsigned Long
    ListJustify As _Byte
End Type

Dim Shared MenusActive As Long
ReDim Shared Menu(10) As MenuType
ReDim Shared MenuList(32767, 10) As String 'Up to 32,767 items max in our list.
ReDim Shared MenuListDisabled(32767, 10) As _Byte
ReDim Shared MenuDisplayOrder(32767, 10) As Integer
Type LinkType
    one As Long
    another As Long
End Type
ReDim Shared LinkedTo(1000) As LinkType
Dim Shared ScrollDelay As _Float
Dim Shared MouseScroll As Integer

'Before here goes BI file content
'After here goes working program

DefLng A-Z
Screen _NewImage(800, 600, 32)
_ScreenMove _Middle

MainMenu = GetMenuHandle
SetMenuSize MainMenu, 200, 150
SetMenuPosition MainMenu, 100, 100
SetMenuFrame MainMenu, True, Red, Yellow
SetMenuVisible MainMenu, True
SetMenuCaption MainMenu, True, "Name", Black, White, True
SetMenuListProperties MainMenu, Black, 0, Center 'Right 'Left
SetMenuHighLightColor MainMenu, Red
For i = 1 To 23
    Read n$
    AddMenuItem MainMenu, n$
Next

Data Steve,Pete,Bob,Joe,Fred
Data Sam,One,Two,Three,Four
Data Five,Six,Seven,Eight,Nine
Data These,are,all,my,names
Data "Aren't",they,grand

SecondMenu = GetMenuHandle
SetMenuSize SecondMenu, 100, 150
SetMenuPosition SecondMenu, 300, 100
SetMenuFrame SecondMenu, True, Red, Yellow
SetMenuVisible SecondMenu, True
SetMenuCaption SecondMenu, True, "Age", Black, White, True
SetMenuListProperties SecondMenu, Black, 0, Left
SetMenuHighLightColor SecondMenu, Red

For i = 1 To 23
    Read n$
    AddMenuItem SecondMenu, n$
Next

Data 12,23,34,45,56
Data 67,78,89,90,1
Data 9,98,87,76,65
Data 54,43,32,21,10
Data 42,55,12

sortmode = 0: linked = -1: menuon = 1

HideMenuScrollBar MainMenu
LinkMenus MainMenu, SecondMenu

DisableItem MainMenu, 5
ScrollDelay = .25
Do
    Cls
    Locate 20, 1: Print "Press <H> to hide the menu."
    Print "Press <S> to show the menu."
    Print "Press <N> for No Sort order."
    Print "Press <A> for Alphabetic Sort order."
    Print "Press <#> for Numeric Sort order."
    Print "Press <C> to toggle case sorting."
    Print "Press <R> to toggle reverse sorting."
    Print "Press <L> to link the menus."
    Print "Press <U> to unlink the menus."
    Print "Press <TAB> to swap between menus."
    Print "<ESC> to quit"
    Print
    Print "Currently: ";
    If sortmode And 1 Then
        Print "ALPHA SORT";
        If kase Then Print ", CASE-SENSITIVE";
        If reversed Then Print ", REVERSE-ORDER" Else Print
    ElseIf sortmode And 2 Then
        Print "NUMERIC SORT";
        If reversed Then Print ", REVERSE-ORDER" Else Print
    Else
        Print "NOT SORTING"
    End If
    Locate 5, 25
    If linked Then Print "LINKED LISTS" Else Print "UNLINKED LISTS"
    Locate 6, 15: Print "MENU ASSOCIATED WITH KEYBOARD: "; menuon

    MouseScroll = 0
    While _MouseInput
        MouseScroll = MouseScroll + _MouseWheel
    Wend

    k = _KeyHit
    Select Case k
        Case Asc("L"), Asc("l"): LinkMenus MainMenu, SecondMenu: linked = -1
        Case Asc("U"), Asc("u"): UnLinkMenus MainMenu, SecondMenu: linked = 0
        Case Asc("H"), Asc("h"): HideMenu menuon
        Case Asc("S"), Asc("s"): ShowMenu menuon
        Case Asc("N"), Asc("n"): sortmode = None: changed = -1: reversed = 0: kase = 0
        Case Asc("A"), Asc("a"): sortmode = Alpha: changed = -1
        Case Asc("#"), Asc("3"): sortmode = Numeric: changed = -1
        Case Asc("C"), Asc("c"): kase = Not kase: changed = -1
        Case Asc("R"), Asc("r"): reversed = Not reversed: changed = -1
        Case 9: menuon = menuon + 1: If menuon = 3 Then menuon = 1
        Case 27: System
    End Select
    If changed Then
        If sortmode <> 0 Then
            If kase Then sortmode = sortmode Or NoCase Else sortmode = sortmode And Not NoCase
            If reversed Then sortmode = sortmode Or Reverse Else sortmode = sortmode And Not Reverse
        End If
        MenuDisplaySort menuon, sortmode
        changed = 0
    End If
    DisplayMenus
    CheckMenus MouseStatus, MenuSelected, OptionSelected
    If MouseStatus <> 0 And MenuSelected <> 0 Then
        If MouseStatus And LeftClick Then
            Locate 1, 1
            Print "You LEFT CLICKED Option #"; OptionSelected; " in Menu #"; MenuSelected
            Print "Which was: "; GetListItem(MenuSelected, OptionSelected)
            Print
            If linked Then
                Print "Since our lists are linked, we get the following items:"; GetListItem(1, OptionSelected), GetListItem(2, OptionSelected)
            Else
                Print "Since our lists are unlinked, we get the following items:"; GetListItem(MenuSelected, OptionSelected)
            End If
            _Display
            _Delay 2 'give it time to pop up
        ElseIf MouseStatus And RightClick Then
            Locate 1, 1
            Print "You RIGHT CLICKED Option #"; OptionSelected; " in Menu #"; MenuSelected
            Print "Which was: "; GetListItem(MenuSelected, OptionSelected)
            Print
            If linked Then
                Print "Since our lists are linked, we get the following items:"; GetListItem(1, OptionSelected), GetListItem(2, OptionSelected)
            Else
                Print "Since our lists are unlinked, we get the following items:"; GetListItem(MenuSelected, OptionSelected)
            End If
            _Display
            _Delay 2 'give it time to pop up
        End If
        Color Yellow
        If MouseStatus And LeftDown Then Locate 35, 1: Print "LEFT MOUSE DOWN over Option #"; OptionSelected; " in Menu #"; MenuSelected
        If MouseStatus And RightDown Then Locate 35, 1: Print "RIGHT MOUSE DOWN over Option #"; OptionSelected; " in Menu #"; MenuSelected
        Color Purple
        If MouseStatus And Hover Then Locate 36, 1: Print "HOVERING over Option #"; OptionSelected; " in Menu #"; MenuSelected;
        Color White

    End If
    _Limit 30
    _Display
Loop



'And here goes the BM routines



Sub LinkMenus (handle1, handle2)
    If handle1 = 0 Or handle2 = 0 Then Error 5: Exit Sub
    If handle1 = handle2 Then Exit Sub 'Why the heck are we linking one list to itself?!
    If Menu(handle1).Valid And Menu(handle2).Valid Then
        LinkMax = LinkedTo(0).one 'I'm using the very first entry into my array to store the number of link entries I have
        'First check to see if the two menus are already linked
        For i = 1 To LinkMax
            found = 0
            If handle1 = LinkedTo(i).one Or handle1 = LinkedTo(i).another Then found = found + 1
            If handle2 = LinkedTo(i).one Or handle2 = LinkedTo(i).another Then found = found + 1
            If found = 2 Then Exit Sub 'the two lists are already linked
            If handle1 = 0 And handle2 = 0 And openspot = 0 Then openspot = i 'we found a spot where a link was freed before; let's use it
        Next
        MenuDisplaySort handle1, None: MenuDisplaySort handle2, None 'unsort the lists to begin with.
        Menu(handle1).TopEntry = 1: Menu(handle2).TopEntry = 1 'and then reset them to their topmost position

        If openspot Then
            LinkedTo(openspot).one = handle1
            LinkedTo(openspot).another = handle2
        Else
            LinkMax = LinkMax + 1: LinkedTo(0).one = LinkMax
            LinkedTo(LinkMax).one = handle1
            LinkedTo(LinkMax).another = handle2
        End If
    Else
        Error 5
    End If
End Sub

Sub UnLinkMenus (handle1, handle2)
    If handle1 = 0 Or handle2 = 0 Then Error 5: Exit Sub 'no list should be linked to 0.  0 is nothing...  Can't free a link to nothing.
    If handle1 = handle2 Then Exit Sub 'We can't unlink a list from itself!
    If Menu(handle1).Valid And Menu(handle2).Valid Then
        For i = 1 To LinkedTo(0).one
            If handle1 = LinkedTo(i).one Or handle1 = LinkedTo(i).another Then found = found + 1
            If handle2 = LinkedTo(i).one Or handle2 = LinkedTo(i).another Then found = found + 1
            If found = 2 Then LinkedTo(i).one = 0: LinkedTo(i).another = 0 'unlink them!
        Next
    Else
        Error 5
    End If
End Sub

Sub DisableItem (handle, item)
    If Menu(handle).Valid Then MenuListDisabled(item, handle) = -1 Else Error 5
End Sub

Sub EnableItem (handle, item)
    If Menu(handle).Valid Then MenuListDisabled(item, handle) = 0 Else Error 5
End Sub

Sub ShowMenu (Handle)
    If Menu(Handle).Valid Then Menu(Handle).Visible = -1 Else Error 5
End Sub

Sub HideMenu (Handle)
    If Menu(Handle).Valid Then Menu(Handle).Visible = 0 Else Error 5
End Sub

Sub ShowMenuScrollBar (Handle)
    If Menu(Handle).Valid Then Menu(Handle).ScrollBarHidden = 0 Else Error 5
End Sub

Sub HideMenuScrollBar (Handle)
    If Menu(Handle).Valid Then Menu(Handle).ScrollBarHidden = -1 Else Error 5
End Sub



Function GetListItem$ (Handle, Item)
    If Menu(Handle).Valid Then
        If Item < 0 Or Item > Menu(Handle).Entries Then Error 5: Exit Function
        GetListItem$ = LTrim$(RTrim$(MenuList(Item, Handle)))
    Else
        Error 5
    End If
End Function



Sub AddMenuItem (Handle, Item$)
    If Menu(Handle).Valid Then
        Menu(Handle).Entries = Menu(Handle).Entries + 1
        MenuList(Menu(Handle).Entries, Handle) = Item$
        MenuDisplayOrder(Menu(Handle).Entries, Handle) = Menu(Handle).Entries
    Else
        Error 5
    End If
End Sub


Sub SetMenuListProperties (Handle, ListColor As _Unsigned Long, ListBackground As _Unsigned Long, ListJustify As _Byte)
    If Menu(Handle).Valid Then
        Menu(Handle).ListColor = ListColor
        Menu(Handle).ListBackground = ListBackground
        Menu(Handle).ListJustify = ListJustify
    Else
        Error 5
    End If
End Sub

Sub SetMenuHighLightColor (Handle, HighLightColor As _Unsigned Long)
    If Menu(Handle).Valid Then
        Menu(Handle).HighLightColor = HighLightColor
    Else
        Error 5
    End If
End Sub


Sub SetMenuCaption (Handle, Header, Caption As String * 255, CaptionColor As _Unsigned Long, CaptionBackground As _Unsigned Long, Xit)
    If Menu(Handle).Valid Then
        Menu(Handle).Header = Header
        Menu(Handle).Caption = Caption
        Menu(Handle).CC = CaptionColor
        Menu(Handle).CBG = CaptionBackground
        Menu(Handle).Exit = Xit
    Else
        Error 5
    End If
End Sub


Sub SetMenuFrame (Handle, HaveFrame, FrameColor As _Unsigned Long, FrameBackGround As _Unsigned Long)
    If Menu(Handle).Valid Then
        Menu(Handle).Frame = HaveFrame
        Menu(Handle).BorderColor = FrameColor
        Menu(Handle).BackgroundColor = FrameBackGround
    Else
        Error 5
    End If
End Sub



Sub SetMenuPosition (Handle, Left, Top)
    If Menu(Handle).Valid Then
        'some basic error checking
        If Top < 0 Then Error 5: Exit Sub 'Let's try and keep the menu on the screen, why don't we
        If Left < 0 Then Error 5: Exit Sub
        If Left > _Width Then Error 5: Exit Sub
        If Top > _Height Then Error 5: Exit Sub
        Menu(Handle).Left = Left
        Menu(Handle).Top = Top
    Else
        Error 5 'toss a generic error if the handle is bad
        'I can add a custom error pop up routine later with appropiate messages
    End If
End Sub


Sub SetMenuVisible (Handle, Visible)
    If Menu(Handle).Valid Then Menu(Handle).Visible = Visible Else Error 5
End Sub

Sub SetMenuSize (Handle, Width, Height)
    If Menu(Handle).Valid Then
        'some basic error checking
        If Width < _FontWidth Then Error 5: Exit Sub 'Can't we at least make a menu which will hold a single character?!
        If Height < _FontHeight Then Error 5: Exit Sub
        If Width > _Width Then Error 5: Exit Sub 'And let's not make it generally larger than our screen, why don't we?!
        If Height > _Height Then Error 5: Exit Sub
        Menu(Handle).Width = Width
        Menu(Handle).Height = Height
    Else
        Error 5 'toss a generic error if the handle is bad
        'I can add a custom error pop up routine later with appropiate messages
    End If
End Sub

Function GetMenuHandle&
    For i = 1 To MenusActive
        If Menu(i).Valid = 0 Then found = i: Exit For
    Next
    If Not found Then
        MenusActive = MenusActive + 1
        found = MenusActive
        u = UBound(Menu)
        Do Until MenusActive < u
            ReDim _Preserve Menu(u + 10) As MenuType
            ReDim _Preserve MenuList(32767, u + 10) As String
            ReDim _Preserve MenuDisplayOrder(32767, u + 10) As Integer
            ReDim _Preserve MenuListDisabled(32767, u + 10) As _Byte
            u = UBound(Menu)
        Loop
    End If
    GetMenuHandle& = found
    Menu(found).Valid = -1 'and let's make this a valid handle
End Function


Sub CheckMenus (MouseStatus As Long, MenuSelected As Long, OptionSelected As Long)

    MenuSelected = 0: OptionSelected = 0
    For i = 1 To MenusActive
        If Menu(i).Visible And Menu(i).Valid Then
            If startnum = 0 Then startnum = i
            ProcessMenu i, startnum, MouseStatus, MenuSelected, OptionSelected
            If MenuSelected Then Exit Sub
        End If
    Next
End Sub


Sub DisplayMenus
    FC = _DefaultColor: BG = _BackgroundColor
    For Whichone = 1 To MenusActive
        If Menu(Whichone).Visible Then
            'Get the starting limits of where menu/list text can appear
            x1 = Menu(Whichone).Left: x2 = x1 + Menu(Whichone).Width
            y1 = Menu(Whichone).Top: y2 = Menu(Whichone).Top + Menu(Whichone).Height
            caption$ = LTrim$(RTrim$(Menu(Whichone).Caption)) 'strip unneeded spaces from the caption (WhichOnef any)

            'clear the background
            Line (Menu(Whichone).Left, Menu(Whichone).Top)-Step(Menu(Whichone).Width, Menu(Whichone).Height), Menu(Whichone).BackgroundColor, BF
            'draw the frame; adjust text limits
            If Menu(Whichone).Frame Then
                Line (Menu(Whichone).Left, Menu(Whichone).Top)-Step(Menu(Whichone).Width, Menu(Whichone).Height), Menu(Whichone).BorderColor, B
                x1 = x1 + 1: y1 = y1 + 1
                x2 = x2 - 1: y2 = y2 - 1
            End If
            If Menu(Whichone).Header Then
                temp = x2 - x1 + 1
                Line (x1, y1)-(x2, y1 + _FontHeight), Menu(Whichone).CBG, BF
                If Menu(Whichone).Exit Then
                    temp = temp - _FontWidth * 2
                    ex1 = x2 - 1 - _FontWidth: ex2 = ex1 + _FontWidth
                    ey1 = y1 + 1: ey2 = ey1 + _FontHeight - 3
                    Line (ex1, ey1)-(ex2, ey2), Red, BF
                    Line (ex1, ey1)-(ex2, ey2), Black
                    Line (ex1, ey2)-(ex2, ey1), Black
                End If
                Do Until _PrintWidth(caption$) <= temp
                    caption$ = Left$(caption$, Len(caption$) - 1)
                Loop
                Color Menu(Whichone).CC, Menu(Whichone).CBG
                _PrintString (x1 + (temp - _PrintWidth(caption$)) \ 2, y1), caption$
                y1 = y1 + _FontHeight
                If Menu(Whichone).Frame Then
                    Line (x1, y1)-(x2, y1), Menu(Whichone).BorderColor
                    y1 = y1 + 2
                End If
            End If 'end header creation

            If Menu(Whichone).Entries > 0 Then 'We have items in our list to display!
                If Menu(Whichone).TopEntry < 1 Then Menu(Whichone).TopEntry = 1 'check to make certain we're displaying from the first entry on at least
                If Menu(Whichone).TopEntry > Menu(Whichone).Entries Then Menu(Whichone).TopEntry = Menu(Whichone).Entries
                printlimit = (x2 - x1 + 1) \ _FontWidth
                limitfound = 1 + (y2 - y1 + 1) \ _FontHeight - 1
                If limitfound > Menu(Whichone).Entries Then
                    limitfound = Menu(Whichone).Entries
                Else
                    scrollneeded = -1
                    printlimit = printlimit - 1
                End If
                Color Menu(Whichone).ListColor, Menu(Whichone).ListBackground
                If Menu(Whichone).ScrollBarHidden = -1 Then scrollneeded = 0
                Dim r As _Unsigned _Byte, g As _Unsigned _Byte, b As _Unsigned _Byte
                Dim CC As Integer

                r = _Red32(Menu(Whichone).BackgroundColor)
                g = _Green32(Menu(Whichone).BackgroundColor)
                b = _Blue32(Menu(Whichone).BackgroundColor)
                Fade& = _RGBA32(r, g, b, 180)

                Select Case Menu(Whichone).ListJustify
                    Case Left
                        For j = 1 To limitfound
                            CC = MenuDisplayOrder(Menu(Whichone).TopEntry + j - 1, Whichone) 'currentchoice
                            graybox = 0
                            t$ = RTrim$(LTrim$(MenuList(CC, Whichone)))
                            If MenuListDisabled(CC, Whichone) Then graybox = -1
                            For ii = 1 To LinkedTo(0).one
                                If Whichone = LinkedTo(ii).one And MenuListDisabled(CC, LinkedTo(ii).another) Then graybox = -1
                                If Whichone = LinkedTo(ii).another And MenuListDisabled(CC, LinkedTo(ii).one) Then graybox = -1
                            Next
                            t$ = Left$(t$, printlimit)
                            _PrintString (x1, y1 + (j - 1) * _FontHeight), t$
                            If graybox Then Line (x1, y1 + (j - 1) * _FontHeight)-(x2, y1 + (j) * _FontHeight), Fade&, BF
                        Next
                    Case Right
                        For j = 1 To limitfound
                            CC = MenuDisplayOrder(Menu(Whichone).TopEntry + j - 1, Whichone) 'currentchoice
                            graybox = 0
                            t$ = RTrim$(LTrim$(MenuList(MenuDisplayOrder(Menu(Whichone).TopEntry + j - 1, Whichone), Whichone)))
                            If MenuListDisabled(CC, Whichone) Then graybox = -1
                            For ii = 1 To LinkedTo(0).one
                                If Whichone = LinkedTo(ii).one And MenuListDisabled(CC, LinkedTo(ii).another) Then graybox = -1
                                If Whichone = LinkedTo(ii).another And MenuListDisabled(CC, LinkedTo(ii).one) Then graybox = -1
                            Next

                            t$ = LTrim$(Left$(t$, printlimit))
                            p = _PrintWidth(t$)
                            If scrollneeded Then
                                _PrintString (x2 - p - _FontWidth, y1 + (j - 1) * _FontHeight), t$
                            Else
                                _PrintString (x2 - p, y1 + (j - 1) * _FontHeight), t$
                            End If
                            If graybox Then Line (x1, y1 + (j - 1) * _FontHeight)-(x2, y1 + (j) * _FontHeight), Fade&, BF
                        Next
                    Case Center
                        For j = 1 To limitfound
                            CC = MenuDisplayOrder(Menu(Whichone).TopEntry + j - 1, Whichone) 'currentchoice
                            graybox = 0
                            t$ = LTrim$(MenuList(MenuDisplayOrder(Menu(Whichone).TopEntry + j - 1, Whichone), Whichone))
                            If MenuListDisabled(CC, Whichone) Then graybox = -1
                            For ii = 1 To LinkedTo(0).one
                                If Whichone = LinkedTo(ii).one And MenuListDisabled(CC, LinkedTo(ii).another) Then graybox = -1
                                If Whichone = LinkedTo(ii).another And MenuListDisabled(CC, LinkedTo(ii).one) Then graybox = -1
                            Next
                            t$ = LTrim$(RTrim$(Left$(t$, printlimit)))
                            p = _PrintWidth(t$)
                            _PrintString ((x2 - x1 + 1) - p \ 2, y1 + (j - 1) * _FontHeight), t$
                            If graybox Then Line (x1, y1 + (j - 1) * _FontHeight)-(x2, y1 + (j) * _FontHeight), Fade&, BF
                        Next
                    Case Else
                        For j = 1 To limitfound
                            CC = MenuDisplayOrder(Menu(Whichone).TopEntry + j - 1, Whichone) 'currentchoice
                            graybox = 0
                            t$ = RTrim$(LTrim$(MenuList(CC, Whichone)))
                            If MenuListDisabled(CC, Whichone) Then graybox = -1
                            For ii = 1 To LinkedTo(0).one
                                If Whichone = LinkedTo(ii).one And MenuListDisabled(CC, LinkedTo(ii).another) Then graybox = -1
                                If Whichone = LinkedTo(ii).another And MenuListDisabled(CC, LinkedTo(ii).one) Then graybox = -1
                            Next
                            t$ = Left$(t$, printlimit)
                            _PrintString (x1, y1 + (j - 1) * _FontHeight), t$
                            If graybox Then Line (x1, y1 + (j - 1) * _FontHeight)-(x2, y1 + (j) * _FontHeight), Fade&, BF
                        Next
                        Menu(Whichone).ListJustify = Left 'If it's not specified for some reason, let's make it left justified as default
                End Select
            End If 'end of displaying items
            If scrollneeded Then 'then we need a vertical scroll bar
                barx1 = x2 - _FontWidth - 1
                barx2 = barx1 + _FontWidth
                Line (barx1, y1)-(barx2, y2), LightGray, BF
                Color Black, DarkGray
                _PrintString (barx1, y1), ""
                _PrintString (barx1, y2 - _FontHeight), ""
            End If
        End If
    Next
    Color FC, BG
End Sub



Sub ProcessMenu (WhichOne As Long, StartNum As Long, MouseStatus As Long, MenuSelected As Long, OptionSelected As Long)
    Static OldMouse As _Byte, ElapsedTimer As _Float, Click As _Byte
    Static ScrollAble As _Byte, OldMouse2 As _Byte, Click2 As _Byte
    MX = _MouseX: MY = _MouseY: MB = _MouseButton(1): MB2 = _MouseButton(2)
    If ScrollDelay < 0 Then ScrollDelay = 0

    'Get the starting limits of where menu/list text can appear
    x1 = Menu(WhichOne).Left: x2 = x1 + Menu(WhichOne).Width
    y1 = Menu(WhichOne).Top: y2 = Menu(WhichOne).Top + Menu(WhichOne).Height
    If WhichOne = StartNum Then
        If OldMouse = 0 And MB = -1 Then Click = -1 Else Click = 0
        If OldMouse2 = 0 And MB2 = -1 Then Click2 = -1 Else Click2 = 0
        OldMouse = MB: OldMouse2 = MB2
        If ElapsedTimer + ScrollDelay < Timer(0.01) Then
            ElapsedTimer = Timer(0.01)
            ScrollAble = -1
        Else
            ScrollAble = 0
        End If
    End If




    If Menu(WhichOne).Frame Then
        Line (Menu(WhichOne).Left, Menu(WhichOne).Top)-Step(Menu(WhichOne).Width, Menu(WhichOne).Height), Menu(WhichOne).BorderColor, B
        x1 = x1 + 1: y1 = y1 + 1
        x2 = x2 - 1: y2 = y2 - 1
    End If
    If Menu(WhichOne).Header Then
        temp = x2 - x1 + 1
        If Menu(WhichOne).Exit Then
            temp = temp - _FontWidth * 2
            ex1 = x2 - 1 - _FontWidth: ex2 = ex1 + _FontWidth
            ey1 = y1 + 1: ey2 = ey1 + _FontHeight - 3
        End If
        y1 = y1 + _FontHeight
        If Menu(WhichOne).Frame Then y1 = y1 + 2
    End If 'end header creation

    If Menu(WhichOne).Entries > 0 Then 'We have items in our list to display!
        If Menu(WhichOne).TopEntry < 1 Then Menu(WhichOne).TopEntry = 1 'check to make certain we're displaying from the first entry on at least
        If Menu(WhichOne).TopEntry > Menu(WhichOne).Entries Then Menu(WhichOne).TopEntry = Menu(WhichOne).Entries
        printlimit = (x2 - x1 + 1) \ _FontWidth
        limitfound = 1 + (y2 - y1 + 1) \ _FontHeight - 1
        If limitfound > Menu(WhichOne).Entries Then
            limitfound = Menu(WhichOne).Entries
        Else
            scrollneeded = -1
            printlimit = printlimit - 1
        End If
    End If 'end of displaying items

    If Menu(WhichOne).ScrollBarHidden = -1 Then scrollneeded = 0

    If scrollneeded Then 'then we need a vertical scroll bar
        barx1 = x2 - _FontWidth - 1
        barx2 = barx1 + _FontWidth
    End If


    Select Case MY 'let's determine which line we clicked the mouse on
        Case Is < ey1 'do nothing as it's too far up the screen to be a click in this box
        Case Is > y2 'do nothing again as it's too far down the screen to be a click in this box
        Case ey1 To ey2 'we've clicked on the line where the EXIT button might exist
        Case y1 To y2
    End Select



    Select Case MY 'let's determine which line we clicked the mouse on
        Case Is < ey1 'do nothing as it's too far up the screen to be a click in this box
        Case Is > y2 'do nothing again as it's too far down the screen to be a click in this box
        Case ey1 To ey2 'we've clicked on the line where the EXIT button might exist
            If Click And Menu(WhichOne).Exit Then
                If MX >= ex1 And MX <= ex2 Then Menu(WhichOne).Visible = False 'If the exit button is available, and we click it, it closes the menu/list
            End If
        Case y1 To y2
            done = 0
            If barx1 > 0 Then p2 = barx1 - 1 Else p2 = x2
            If MX >= x1 And MX <= p2 Then 'highlight the choice the user is over
                yPOS = ((MY - y1 + 1) \ _FontHeight) * _FontHeight + y1
                If yPOS + _FontHeight <= y2 Then Line (x1, yPOS)-(p2, yPOS + _FontHeight), Menu(WhichOne).HighLightColor, B
            End If

            If MouseScroll Then
                If MX >= x1 And MX <= x2 Then
                    Menu(WhichOne).TopEntry = Menu(WhichOne).TopEntry + MouseScroll
                    If Menu(WhichOne).TopEntry < 1 Then Menu(WhichOne).TopEntry = 1
                    If Menu(WhichOne).TopEntry > Menu(WhichOne).Entries - limitfound + 1 Then Menu(WhichOne).TopEntry = Menu(WhichOne).Entries - limitfound + 1
                    For i = 1 To LinkedTo(0).one
                        If WhichOne = LinkedTo(i).one Then Menu(LinkedTo(i).another).TopEntry = Menu(WhichOne).TopEntry
                        If WhichOne = LinkedTo(i).another Then Menu(LinkedTo(i).one).TopEntry = Menu(WhichOne).TopEntry
                    Next
                End If
            End If

            If scrollneeded Then
                If MY >= y1 And MY <= y1 + _FontHeight And MX >= barx1 And MX <= barx2 And MB <> 0 Then 'it's the top scroll bar
                    If ScrollAble Then Menu(WhichOne).TopEntry = Menu(WhichOne).TopEntry - 1
                    If Menu(WhichOne).TopEntry < 1 Then Menu(WhichOne).TopEntry = 1
                    done = -1
                    For i = 1 To LinkedTo(0).one
                        If WhichOne = LinkedTo(i).one Then Menu(LinkedTo(i).another).TopEntry = Menu(WhichOne).TopEntry
                        If WhichOne = LinkedTo(i).another Then Menu(LinkedTo(i).one).TopEntry = Menu(WhichOne).TopEntry
                    Next
                ElseIf MY >= y2 - _FontHeight And MY <= y2 And MX >= barx1 And MX <= barx2 And MB <> 0 Then 'it's the bottom scroll bar
                    If ScrollAble Then Menu(WhichOne).TopEntry = Menu(WhichOne).TopEntry + 1
                    If Menu(WhichOne).TopEntry > Menu(WhichOne).Entries - limitfound + 1 Then Menu(WhichOne).TopEntry = Menu(WhichOne).Entries - limitfound + 1
                    done = -1
                    For i = 1 To LinkedTo(0).one
                        If WhichOne = LinkedTo(i).one Then Menu(LinkedTo(i).another).TopEntry = Menu(WhichOne).TopEntry
                        If WhichOne = LinkedTo(i).another Then Menu(LinkedTo(i).one).TopEntry = Menu(WhichOne).TopEntry
                    Next
                ElseIf MX >= barx1 And MX <= barx2 And MB <> 0 Then
                    MenuLimit = Menu(WhichOne).Entries - limitfound + 2
                    ylimit = y2 - y1 - _FontHeight * 2 + 1
                    yPOS = MY - y1 - _FontHeight + 1
                    Menu(WhichOne).TopEntry = (MenuLimit - (ylimit - yPOS) / ylimit * MenuLimit)
                    If Menu(WhichOne).TopEntry >= MenuLimit Then Menu(WhichOne).TopEntry = MenuLimit - 1
                    done = -1
                    For i = 1 To LinkedTo(0).one
                        If WhichOne = LinkedTo(i).one Then Menu(LinkedTo(i).another).TopEntry = Menu(WhichOne).TopEntry
                        If WhichOne = LinkedTo(i).another Then Menu(LinkedTo(i).one).TopEntry = Menu(WhichOne).TopEntry
                    Next
                End If
            End If

            If Not done Then 'if we've processed a scrollbar event, we're finished
                If MX >= x1 And MX <= x2 Then
                    MenuSelected = WhichOne
                    OptionSelected = MenuDisplayOrder((MY - y1 + 1) \ _FontHeight + Menu(WhichOne).TopEntry, WhichOne)
                    invalidate = 0
                    If MenuListDisabled(OptionSelected, WhichOne) Then invalidate = -1
                    For ii = 1 To LinkedTo(0).one
                        If WhichOne = LinkedTo(ii).one And MenuListDisabled(OptionSelected, LinkedTo(ii).another) Then invalidate = -1
                        If WhichOne = LinkedTo(ii).another And MenuListDisabled(OptionSelected, LinkedTo(ii).one) Then invalidate = -1
                    Next
                    If barx1 <> 0 And MX > barx1 Then invalidate = -1
                    If invalidate Then MenuSelected = 0: OptionSelected = 0
                End If
            End If
    End Select


    MouseStatus = 0
    MouseStatus = MouseStatus Or -Click 'leftclick
    MouseStatus = MouseStatus Or Click2 * -2 'rightclick
    MouseStatus = MouseStatus Or _MouseButton(1) * -4 'leftdown
    MouseStatus = MouseStatus Or _MouseButton(2) * -8 'rightdown
    MouseStatus = MouseStatus Or (MenuSelected <> 0) * 16 'If we're over the menu, we're hovering

End Sub


Sub MenuDisplaySort (handle As Long, sortmethod As _Byte)
    gap = Menu(handle).Entries

    If sortmethod And Alpha Then
        If sortmethod And NoCase Then
            Do
                gap = 10 * gap \ 13
                If gap < 1 Then gap = 1
                i = 0
                swapped = 0
                Do
                    t$ = UCase$(LTrim$(RTrim$(MenuList(MenuDisplayOrder(i, handle), handle))))
                    t1$ = UCase$(LTrim$(RTrim$(MenuList(MenuDisplayOrder(i + gap, handle), handle))))
                    If t$ > t1$ Then
                        Swap MenuDisplayOrder(i, handle), MenuDisplayOrder(i + gap, handle)
                        For ii = 1 To LinkedTo(0).one
                            If handle = LinkedTo(ii).one Then Swap MenuDisplayOrder(i, LinkedTo(ii).another), MenuDisplayOrder(i + gap, LinkedTo(ii).another)
                            If handle = LinkedTo(ii).another Then Swap MenuDisplayOrder(i, LinkedTo(ii).one), MenuDisplayOrder(i + gap, LinkedTo(ii).one)
                        Next
                        swapped = -1
                    End If
                    i = i + 1
                Loop Until i + gap > Menu(handle).Entries
            Loop Until gap = 1 And swapped = 0
        Else
            Do
                gap = 10 * gap \ 13
                If gap < 1 Then gap = 1
                i = 0
                swapped = 0
                Do
                    t$ = LTrim$(RTrim$(MenuList(MenuDisplayOrder(i, handle), handle)))
                    t1$ = LTrim$(RTrim$(MenuList(MenuDisplayOrder(i + gap, handle), handle)))
                    If t$ > t1$ Then
                        Swap MenuDisplayOrder(i, handle), MenuDisplayOrder(i + gap, handle)
                        For ii = 1 To LinkedTo(0).one
                            If handle = LinkedTo(ii).one Then Swap MenuDisplayOrder(i, LinkedTo(ii).another), MenuDisplayOrder(i + gap, LinkedTo(ii).another)
                            If handle = LinkedTo(ii).another Then Swap MenuDisplayOrder(i, LinkedTo(ii).one), MenuDisplayOrder(i + gap, LinkedTo(ii).one)
                        Next
                        swapped = -1
                    End If
                    i = i + 1
                Loop Until i + gap > Menu(handle).Entries
            Loop Until gap = 1 And swapped = 0
        End If
        If sortmethod And Reverse Then
            For i = 1 To Menu(handle).Entries \ 2
                Swap MenuDisplayOrder(i, handle), MenuDisplayOrder(Menu(handle).Entries - i + 1, handle)
                For ii = 1 To LinkedTo(0).one
                    If handle = LinkedTo(ii).one Then Swap MenuDisplayOrder(i, LinkedTo(ii).another), MenuDisplayOrder(Menu(handle).Entries - i + 1, LinkedTo(ii).another)
                    If handle = LinkedTo(ii).another Then Swap MenuDisplayOrder(i, LinkedTo(ii).one), MenuDisplayOrder(Menu(handle).Entries - i + 1, LinkedTo(ii).one)
                Next
            Next
        End If
    ElseIf sortmethod And Numeric Then
        Do
            gap = 10 * gap \ 13
            If gap < 1 Then gap = 1
            i = 0
            swapped = 0
            Do
                If Val(MenuList(MenuDisplayOrder(i, handle), handle)) > Val(MenuList(MenuDisplayOrder(i + gap, handle), handle)) Then
                    Swap MenuDisplayOrder(i, handle), MenuDisplayOrder(i + gap, handle)
                    For ii = 1 To LinkedTo(0).one
                        If handle = LinkedTo(ii).one Then Swap MenuDisplayOrder(i, LinkedTo(ii).another), MenuDisplayOrder(i + gap, LinkedTo(ii).another)
                        If handle = LinkedTo(ii).another Then Swap MenuDisplayOrder(i, LinkedTo(ii).one), MenuDisplayOrder(i + gap, LinkedTo(ii).one)
                    Next
                    swapped = -1
                End If
                i = i + 1
            Loop Until i + gap > Menu(handle).Entries
        Loop Until gap = 1 And swapped = 0
        If sortmethod And Reverse Then
            For i = 1 To Menu(handle).Entries \ 2
                Swap MenuDisplayOrder(i, handle), MenuDisplayOrder(Menu(handle).Entries - i + 1, handle)
                For ii = 1 To LinkedTo(0).one
                    If handle = LinkedTo(ii).one Then Swap MenuDisplayOrder(i, LinkedTo(ii).another), MenuDisplayOrder(Menu(handle).Entries - i + 1, LinkedTo(ii).another)
                    If handle = LinkedTo(ii).another Then Swap MenuDisplayOrder(i, LinkedTo(ii).one), MenuDisplayOrder(Menu(handle).Entries - i + 1, LinkedTo(ii).one)
                Next
            Next
        End If
    Else
        For i = 1 To Menu(handle).Entries
            MenuDisplayOrder(i, handle) = i
            For ii = 1 To LinkedTo(0).one
                If handle = LinkedTo(ii).one Then MenuDisplayOrder(i, LinkedTo(ii).another) = i
                If handle = LinkedTo(ii).another Then MenuDisplayOrder(i, LinkedTo(ii).one) = i
            Next
        Next
    End If

End Sub

This is an old example, but one which I've used for a lot of different things over time.  Here we generate a 2-field database (Name and Age), and it displays both of those fields.  You can link those fields together and use one of control the other (sort by age and the names change to match your sorting), or you can break them apart and only work in one without regard to what the other displays (for completely independent lists).

As far as most menu type things go for me, this type of routine is one that I tend to plug in and make a use of a *lot* for my personal work.  For example, I might have an MP3 player which contains the following information:

Song Name -- Artist -- Length -- Format -- Drive Location

Just zap it into the above and now I can display and sort and scroll by any of those fields as I desire, and click on whatever file/field I want, with just a scroll/click of the button.  Wink
Reply


Messages In This Thread
RE: What do you guys like to use for mouse mapping? - by SMcNeill - 12-24-2024, 04:20 AM



Users browsing this thread: 11 Guest(s)