Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What do you guys like to use for mouse mapping?
#1
Arrays is one way to go, but I got used to using a non-array method many moons ago. (_|_)

Code: (Select All)
Locate 2
text$ = "Demo of mapping technique"
Print center$(text$)
text$ = "for mouse menu selection."
Print center$(text$)
_Delay 4
Print
text$ = "Watch as the program maps."
Print center$(text$)
text$ = "the menu at the bottom..."
Print center$(text$)
y = CsrLin: x = Pos(0)
a$ = "[F1] Help  [F5] Save  [Enter] Laugh at Steve  [Esc] Quit"
Locate _Height, _Width \ 2 - Len(a$) \ 2 + 1: Print a$;
Locate _Height - 2, 1
For i = 1 To _Width ' Convert to width.
    f$ = f$ + Chr$(Screen(_Height, i))
Next
_Delay 2: Color 8, 0
temp$ = " "
For i = 1 To Len(f$) ' Map mouse hot zones.
    x$ = Mid$(f$, i, 1)
    If hot Then
        If Left$(LTrim$(Mid$(f$, i) + "["), 1) = "[" Then
            hot = 1 - hot
            temp$ = " "
        End If
    End If
    If x$ <> Chr$(32) And hot = 0 Then
        hot = 1 - hot
        j = j + 1
        temp$ = Chr$(96 + j)
    End If
    map$ = map$ + temp$
    Print LTrim$(Str$(hot));: _Delay .1
Next
Locate _Height - 1, 1: Print map$;
Locate y, x
Color 7, 0
Print
text$ = "Now try the Mouse by clicking a"
Print center$(text$)
text$ = "selection from the bottom menu."
Print center$(text$)
Print
y = CsrLin
Do
    _Limit 30

    MyMouse_and_Keyboard lb, mb, rb, my, mx, mw, shift%, clkcnt, drag, b$

    If lb = 2 And my = _Height Then
        Select Case Asc(Mid$(map$, mx, 1)) - 96
            Case 1: b$ = "F1"
            Case 2: b$ = "F5"
            Case 3: b$ = "Enter"
            Case 4: b$ = "Esc"
        End Select
    End If
    If Len(b$) Then
        Select Case b$
            Case Chr$(0) + Chr$(59), "F1"
                text$ = "You selected: Help"
                Locate y: Print Space$(_Width - 1);
                Print center$(text$)
            Case Chr$(0) + Chr$(63), "F5"
                text$ = "You selected: Save"
                Locate y: Print Space$(_Width - 1);
                Print center$(text$)
            Case Chr$(13), "Enter"
                text$ = "You selected: Laugh at Steve. Great choice!"
                Locate y: Print Space$(_Width - 1);
                Print center$(text$)
            Case Chr$(27), "Esc"
                text$ = "You selected: Quit. See you later!"
                Locate y: Print Space$(_Width - 1);
                Print center$(text$)
                _Delay 4
                System
        End Select
    End If
Loop

Function center$ (text$)
    Locate , _Width \ 2 - Len(text$) \ 2 + 1
    center$ = text$
End Function

Sub MyMouse_and_Keyboard (lb, mb, rb, my, mx, mw, shift%, clkcnt, drag, b$)
    Static oldmy, oldmx, z1, hover, mwy, oldmwy
    If Len(autokey$) Then
        b$ = Mid$(autokey$, 1, InStr(autokey$ + ",", ",") - 1)
        autokey$ = Mid$(autokey$, InStr(autokey$ + ",", ",") + 1)
    Else
        b$ = InKey$
    End If
    If z1 Then If Abs(Timer - z1) > .3 Then z1 = 0: clkcnt = 0
    If lb > 0 Then
        If lb = 1 Then
            lb = -1
        Else
            lb = 0
        End If
    End If
    If rb > 0 Then If rb = 1 Then rb = -1 Else rb = 0
    If mb > 0 Then If mb = 1 Then mb = -1 Else mb = 0
    While _MouseInput
        mwy = mwy + _MouseWheel
    Wend
    my = _MouseY
    mx = _MouseX
    b_hover = 0
    For i = 1 To nob ' number of buttons.
        If my >= y_btl(i) And my <= y_bbr(i) And mx >= x_btl(i) And mx <= x_bbr(i) Then
            b_hover = i
            Exit For
        End If
    Next
    If lb = -1 Then
        If oldmy And oldmx <> mx Or oldmy And oldmy <> my Then
            If mx <> oldmx Then drag = Sgn(mx - oldmx) ' Prevent zero which can occur if mouse moves off row when being dragged horizontally.
        End If
    End If
    If drag = 0 Then
        If mwy <> oldmw Then
            mw = Sgn(mwy - oldmwy): mwy = 0
        Else
            mw = 0
        End If
        oldmwy = mwy
        If _KeyDown(100303) Or _KeyDown(100304) Then shift% = -1 Else If shift% Then shift% = 0
    End If
    If lb = -1 And _MouseButton(1) = 0 Then
        lb = 2: drag = 0: hover = 0
    ElseIf rb = -1 And _MouseButton(2) = 0 Then
        rb = 2
    ElseIf mb = -1 And _MouseButton(3) = 0 Then
        mb = 2
    End If
    If _MouseButton(1) Then
        If lb = 0 Then
            lb = 1
            If z1 = 0 Then
                z1 = Timer ' Let first click go through.
            Else
                clkcnt = clkcnt + 1
            End If
        End If
    ElseIf _MouseButton(2) And rb = 0 Then
        rb = 1
    ElseIf _MouseButton(3) And mb = 0 Then
        mb = 1
    End If
    oldmy = my: oldmx = mx
End Sub

Sometimes I just use an Instr() method...

Code: (Select All)
j = _InStrRev(Mid$(f$, 1, mx), "[") + 1
If j Then
    temp$ = RTrim$(Mid$(f$, j, InStr(Mid$(f$, j) + "[", "[") - 1))
    If mx < j + Len(temp$) Then
        If lb = 2 Then
            b$ = Mid$(temp$, 1, InStr(temp$, "]") - 1)
        End If
    End If
End If

So how about everyone else?

Pete
Reply
#2
So verbose Smile

Here a little less LOC:
Code: (Select All)
_Title "Quick Menu" ' b+ 2024-12-20
Screen _NewImage(800, 600, 32): _ScreenMove 250, 60
Dim menu$(1 To 4)
menu$(1) = "Help": menu$(2) = "Save": menu$(3) = "Laugh at Pete's joke": menu$(4) = "Quit"
Cls , &HFF000088: _PrintMode _KeepBackground
Do
sel = getButtonNumberChoice%(menu$())
Print "You picked: "; menu$(sel)
Loop Until sel = 4

Sub drwBtn (x, y, s$) '200 x 50
Dim fc~&, bc~&
Line (x, y)-Step(200, 50), _RGB32(0, 0, 0), BF
Line (x, y)-Step(197, 47), _RGB32(255, 255, 255), BF
Line (x + 1, y + 1)-Step(197, 47), &HFFBABABA, BF
fc~& = _DefaultColor: bc~& = _BackgroundColor ' save color before we chnge
Color _RGB32(0, 0, 0), &HFFBABABA
_PrintString (x + 100 - 4 * Len(s$), y + 17), s$
Color fc~&, bc~& ' restore color
End Sub

'this works pretty good for a menu of buttons to get menu number
Function getButtonNumberChoice% (choice$()) 'this sub uses drwBtn
ub = UBound(choice$): lb = LBound(choice$)
For b = lb To ub ' drawing a column of buttons at _width - 210 starting at y = 10
drwBtn _Width - 210, b * 60 + 10, choice$(b)
Next
Do
While _MouseInput: Wend
mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
If mb Then
_Delay .25 ' delay before exit to give user time to release mouse button
If mx > _Width - 210 And mx <= _Width - 10 Then
For b = lb To ub
If my >= b * 60 + 10 And my <= b * 60 + 60 Then
getButtonNumberChoice% = b: Exit Function
End If
Next
Beep
Else
Beep
End If
End If
_Limit 60
Loop
End Function
b = b + ...
Reply
#3
Hi Pete, I have always been partial to Drop Down Menus. With B+ help I have one that is still very much under construction but here a piece of the code that would give you an idea of the approach I'm now using

Code: (Select All)
Screen _NewImage(1900, 900, 32)
$Color:32
'Color LightGreen
'Menu Item 1
Line (1, 1)-(100, 100), _RGB32(0, 255, 0), BF
Line (3, 3)-(97, 97), _RGB32(0), B
Color Brown, _RGB32(0, 255, 0)
_PrintString (15, 5), "OPENING"
_PrintString (15, 20), "INFO"
Do
    Do While _MouseInput
        '    'INboxX = _MouseX
        '    'INboxY = _MouseY
        For INBX = 1 To 100
            For INBY = 1 To 100

                If _MouseX <> INBX Or _MouseY <> INBY Then
                    x = _MouseX
                    y = _MouseY
                    x$ = Str$(x)
                    y$ = Str$(y)
                    _PrintString (500, 10), "I'm NOT in the menu box"
                    _PrintString (500, 50), x$
                    _PrintString (530, 50), y$
                    _PrintString (500, 10), "                       "
                    Exit For
                ElseIf _MouseX = INBX And _MouseY = INBY Then
                    x = _MouseX
                    y = _MouseY
                    x$ = Str$(x)
                    y$ = Str$(y)
                    _PrintString (500, 10), "I'm in the menu box"
                    _PrintString (500, 50), x$
                    _PrintString (530, 50), y$
                    _PrintString (500, 10), "                  "
                    Exit For
                    'Exit For
                End If


                '_Display
                'Sleep
                '_PrintString (INBX, INBY), "                      "
            Next
            Exit For
        Next

    Loop
Loop Until InKey$ = Chr$(27)
'Do 'main program loop
Reply
#4
And, here some code of how I approached this in the old days, again just an excerpt of many more lines of code

Code: (Select All)
Screen 12
Width 80, 60
PSet (7, 7), 1
Draw "r100 d10 l100 u10"
Sleep
Cls
PSet (7, 7), 1
Draw "r100 d20 l100 u20"
Sleep 1
Cls
PSet (7, 7), 1
Draw "r100 d30 l100 u30"
Sleep 1
Cls
PSet (7, 7), 1
Draw "r100 d40 l100 u40"
Sleep 1
Cls
Locate 2, 2
Print " Menu"
'VIEW (10, 10)-(300, 180), , 1
'LOCATE 1, 11: PRINT "A big graphics viewport";
View Screen(7, 7)-(150, 40), , 2
For x = 1 To 500000: Next
Cls
Locate 2, 2
Print " Menu"
Print " P=Pres Cyc"
'LOCATE 11, 11: PRINT " A small graphics viewport";
View Screen(7, 7)-(150, 50), , 2
Sleep
For x = 1 To 500000: Next
Cls
Locate 2, 2
Print " Menu"
Print " P=Pres Cyc"
Print " H=Cyc History"
View Screen(7, 7)-(150, 60), , 2
'SLEEP
For x = 1 To 500000: Next
Cls
Locate 2, 2
Print " Menu"
Print " P=Pres Cyc"
Print " H=Cyc History"
Print " Q=Cyc Quarters"
View Screen(7, 7)-(150, 70), , 2
'SLEEP
For x = 1 To 500000: Next
Cls
Locate 2, 2
Print " Menu"
Print " P=Pres Cyc"
Print " H=Cyc History"
Print " Q=Cyc Quarters"
Sleep
Reply
#5
Arrays are how I go for complex mouse mapping.  Just store the upper-left and lower-right point of the box where the mouse click is valid.  Most times however, I just assign areas which can be calculated easily with a little math for my mouse areas.

For i = 0 to 5 '5 boxes to click in as a menu
   line (100,i * 100 + 100) - step (400,100), kolor(i), BF 'this is one boxed area
Next  ' this little bit draws the boxes

While _MouseInput: Wend
 If _MouseX > 100 and _MouseX < 500 Then 'it's within the left-right box area
     boxclicked = INT((_MouseY - 100) / 100) 'this tells us if we clicked inside the proper Y area for each designated box.
 End IF

That's all there is to it!  Quick to create, even quicker to check for coordinates.
Reply
#6
@bplus Verbose? What bush whacking, butt munching, monkey thumping thing of a rattlesnake from hell are you bad mouthing, blabbering aimlessly, and yammering about now? Oh, now I get it. Big Grin 

But in my defense, I included a complete mouse routine, centering function, and a text description of the process.... So let's whittle that **** out and we are left with...

Code: (Select All)
a$ = "[F1] Help  [F5] Save  [Enter] Laugh at Steve  [Esc] Quit"
f$ = Space$(_Width): Mid$(f$, _Width \ 2 - Len(a$) \ 2 + 1) = a$
Locate _Height, 1: Print f$;
temp$ = " "
For i = 1 To Len(f$) ' Map mouse hot zones.
    x$ = Mid$(f$, i, 1)
    If hot Then
        If Left$(LTrim$(Mid$(f$, i) + "["), 1) = "[" Then
            hot = 1 - hot: temp$ = " "
        End If
    End If
    If x$ <> Chr$(32) And hot = 0 Then
        hot = 1 - hot: j = j + 1: temp$ = Chr$(96 + j)
    End If
    map$ = map$ + temp$
Next
Do
    _Limit 30
    MyMouse_and_Keyboard lb, my, mx
    If lb And my = _Height Then
        Select Case Asc(Mid$(map$, mx, 1)) - 96
            Case 1: Print "You selected: Help"
            Case 2: Print "You selected: Save"
            Case 3: Print "You selected: Laugh at Steve. Great choice!"
            Case 4: Print "You selected: Quit. See you later!": End
        End Select
    End If
Loop
Sub MyMouse_and_Keyboard (lb, my, mx)
    While _MouseInput: Wend
    my = _MouseY: mx = _MouseX: lb = _MouseButton(1)
    If lb Then _Delay .25
End Sub

So see? Mine's much shorter than anyone's here!!!!!!! (OH SHUT UP, STEVE!)

Pete
Shoot first and shoot people who ask questions, later.
Reply
#7
@Pete Yes I do like your mouse routine that does keypress and all mouse stuff including drag! I should have something like that, I suppose. Maybe even redo my very simple GUI stuff with something like that.

So many different ways to do this, go for most universal sub or go for short and sweet? Just a matter of preference. And sure, interesting to compare how wrong OP's preferences are Big Grin
b = b + ...
Reply
#8
@bplus

Yeah the older I get, the lazier, more like Steve, I become. Nowadays I just paste in my do-it-all mouse routine and others like it. (See, even you liked it!) Big Grin

Seriously, I'm so disorganized that in the past it was just easier to keep coding than go hunting. Honestly others are glad I never took took flying lessons, when I had the opportunity, because although I'm quite capable, I'd have to be the one okay with picking the airport to take off from and everyone else would have to be okay with where the plane landed. Don't look now Mark, but that loud noise coming from the rooftop... it ain't Santa.

+1 on the button design. I have some I think are very much like those... but I'd have to go hunt them down!!!

Pete
Reply
#9
@Pete I am reviewing your Mouse routine and immediately stumped by this autoKey$ business:
Code: (Select All)
Sub MyMouse_and_Keyboard (lb, mb, rb, my, mx, mw, shift%, clkcnt, drag, b$)
    Static oldmy, oldmx, z1, hover, mwy, oldmwy
    If Len(autokey$) Then
        b$ = Mid$(autokey$, 1, InStr(autokey$ + ",", ",") - 1)
        autokey$ = Mid$(autokey$, InStr(autokey$ + ",", ",") + 1)
    Else
        b$ = InKey$
    End If

That is the only place autokey$ is used so the first part of If never is true!

Some may even say it is nonsense, not me, but some might Big Grin

Perhaps an artifact from another sub this code was created from?

Another stumper is nob, never set anywhere only used as below.
Code: (Select All)
For i = 1 To nob ' number of buttons.
        If my >= y_btl(i) And my <= y_bbr(i) And mx >= x_btl(i) And mx <= x_bbr(i) Then
            b_hover = i
            Exit For
        End If
    Next
This loop really isn't. Hoover can only occur over button one? nawh.

I am thinking of getting generic sub going and testing in old programs and want really tight code.
b = b + ...
Reply
#10
Here's a quick demo of what I was talking of.  Just some basic math for input areas.  Tongue

Code: (Select All)
$Color:32
Data One,Two,Three,Four,Five,Six,Seven,Eight,Nine
Screen _NewImage(640, 480, 32)
Dim Shared Caption(1 To 3, 1 To 3) As String
Dim As _Unsigned _Integer64 num, c
For x = 1 To 3: For y = 1 To 3: Read Caption(x, y): Next y, x

Do
DrawMenus
c = CheckMenus
If c Then num = 10&& * num + c
Locate 1, 1: Print num,
If c <> 0 Then Print c
_Limit 30
Loop Until _MouseButton(2) Or _KeyDown(27) Or num > 123456789123456789
System


Sub DrawMenus
For x = 1 To 3
For y = 1 To 3
Line (120 * x, 100 * y)-Step(120, 100), White, B
_PrintString (120 * x + 60 - .5 * _PrintWidth(Caption(x, y)), 100 * y + 50 - .5 * _FontHeight), Caption(x, y)
Next
Next
End Sub

Function CheckMenus
Static oldmouse
While _MouseInput: Wend
xp = Int(_MouseX / 120): yp = Int(_MouseY / 100)
If xp > 0 And xp < 4 And yp > 0 And yp < 4 Then t = xp * 3 + yp - 3
If _MouseButton(1) And Not oldmouse Then CheckMenus = t
oldmouse = _MouseButton(1)
End Function

(12-22-2024, 01:53 AM)bplus Wrote: @Pete I am reviewing your Mouse routine and immediately stumped by this autoKey$ business:
Code: (Select All)
Sub MyMouse_and_Keyboard (lb, mb, rb, my, mx, mw, shift%, clkcnt, drag, b$)
    Static oldmy, oldmx, z1, hover, mwy, oldmwy
    If Len(autokey$) Then
        b$ = Mid$(autokey$, 1, InStr(autokey$ + ",", ",") - 1)
        autokey$ = Mid$(autokey$, InStr(autokey$ + ",", ",") + 1)
    Else
        b$ = InKey$
    End If

That is the only place autokey$ is used so the first part of If never is true!

Some may even say it is nonsense, not me, but some might Big Grin

Perhaps an artifact from another sub this code was created from?
Code: (Select All)
    For i = 1 To nob ' number of buttons.
        If my >= y_btl(i) And my <= y_bbr(i) And mx >= x_btl(i) And mx <= x_bbr(i) Then
            b_hover = i
            Exit For
        End If
    Next

Pete's saying you can code yourself a set of autokeys to process...  
autokey$ = "A,B,C,D"  'for example

Then the above would take "A" as the first key press, process it as b$, and make autokey$ = "B,C,D".

It's for processing comma delimited key strings.  Wink
Reply




Users browsing this thread: 6 Guest(s)