Code: (Select All)
'+--------------------------------------------------------------+
'| Ritchie's mouse routines |
'| 08/13/23 |
'| Written in QB64 Phoenix Edition v3.8.0 |
'| Should function correctly in any version of QB64 however. |
'| |
'| Just playing around one day and came up with these routines. |
'| Use them as a basis for your project, such as a GUI or a |
'| mouse driven game. |
'| Hack and use these routines as you wish. |
'| |
'| Code includes a simple program section showing use. |
'| |
'| Scroll to the bottom of the code for documentation. |
'+--------------------------------------------------------------+
OPTION _EXPLICIT ' declare those variables son!
CONST FALSE = 0, TRUE = NOT FALSE ' truth detectors
CONST NORMALSELECT = 0 ' mouse pointer names and their associated value
CONST HELPSELECT = 1
CONST WORKINGINBACKGROUND = 2
CONST BUSY = 3
CONST PRECISIONSELECT = 4
CONST TEXTSELECT = 5
CONST HANDWRITING = 6
CONST UNAVAILABLE = 7
CONST VERTICALRESIZE = 8
CONST HORIZONTALRESIZE = 9
CONST DIAGONALRESIZE1 = 10
CONST DIAGONALRESIZE2 = 11
CONST MOVE = 12
CONST ALTERNATESELECT = 13
CONST LINKSELECT = 14
TYPE TYPE_VECTOR ' VECTOR PROPERTIES
x AS SINGLE ' x coordinate
y AS SINGLE ' y coordinate
END TYPE
TYPE TYPE_AREA ' AREA PROPERTIES
Min AS TYPE_VECTOR ' upper left coordinate
Max AS TYPE_VECTOR ' lower right coordinate
END TYPE
TYPE TYPE_ZONE ' ZONE PROPERTIES
Area AS TYPE_AREA ' zone area
Active AS INTEGER ' zone is available to mouse (t/f)
END TYPE
TYPE TYPE_POINTER ' MOUSE POINTER PROPERTIES
Value AS INTEGER ' pointer number
Image AS LONG ' pointer image
Offset AS TYPE_VECTOR ' pointer image offset from mousex, mousey
END TYPE
TYPE TYPE_MOUSEBUTTON ' MOUSE BUTTON PROPERTIES
Button AS INTEGER ' _MOUSEBUTTON(1-3)
Held AS INTEGER ' button held down (t/f)
DCTime AS DOUBLE ' double click time interval
DCTimer AS DOUBLE ' time between 2 subsequent clicks
Clicked AS INTEGER ' button clicked (t/f)
DoubleClicked AS INTEGER ' button double clicked (t/f)
END TYPE
TYPE TYPE_MOUSE ' MOUSE PROPERTIES
Location AS TYPE_VECTOR ' current mouse location
Previous AS TYPE_VECTOR ' previous mouse location
Right AS TYPE_MOUSEBUTTON ' right mouse button properties
Left AS TYPE_MOUSEBUTTON ' left mouse button properties
Middle AS TYPE_MOUSEBUTTON ' middle mouse button properties
Vector AS TYPE_VECTOR ' vector from previous location to current
Normal AS TYPE_VECTOR ' normalized vector from previous location to current
Degree AS SINGLE ' angle from previous location to current
Speed AS SINGLE ' speed of mouse from previous location to current
Wheel AS INTEGER ' wheel turns counted
Pointer AS TYPE_POINTER ' mouse pointer properties
ZoneTrap AS INTEGER ' zone area mouse trapped in (0 for none)
Hovering AS INTEGER ' zone area mouse is hovering (0 for none)
Area AS TYPE_AREA ' area mouse is trapped within (if ZoneTrap > 0)
END TYPE
REDIM Zone(0) AS TYPE_ZONE ' mouse zones
DIM Mouse AS TYPE_MOUSE ' mouse properties
DIM Pointer(14) AS TYPE_POINTER ' mouse pointer images
'+------------------------+
'| Begin demo use of code | <<------------------------------------------------------------------------------------------------------------------------
'+------------------------+
DIM AS INTEGER Zone1, Zone2, Zone3, Zone4, Zone5 ' handles for mouse zone areas
SCREEN _NEWIMAGE(800, 600, 32) ' graphics screen
Initialize ' initialize mouse
_TITLE "Mouse Utilities" ' window title
_MOUSEHIDE ' hide system mouse
'+--------------------------+
'| Create a few mouse zones |
'+--------------------------+
Zone1 = DefineMouseZone(10, 10, 80, 80, TRUE) ' (x1, y1, width, height, Active)
Zone2 = DefineMouseZone(100, 10, 80, 80, TRUE)
Zone3 = DefineMouseZone(10, 100, 170, 80, TRUE)
Zone4 = DefineMouseZone(190, 10, 170, 170, TRUE)
Zone5 = DefineMouseZone(10, 190, 350, 350, TRUE)
'+-----------+
'| Main loop |
'+-----------+
DO
_LIMIT 15 ' stay at or above 15 or greater for best results (sometimes double click gets missed with a lower frame rate)
CLS
UpdateMouse ' update mouse information
DrawBorder 0 ' draw borders around all zones
IF AnyClick THEN SOUND 440, 1 ' sound when click occurs
IF AnyDoubleClick THEN SOUND 880, 1 ' sound octave higher when double click occurs
IF SGN(MouseWheel) THEN SetMousePointer MousePointer + SGN(MouseWheel) ' select mouse pointer
LOCATE 2, 50: PRINT "AnyClick : "; AnyClick
LOCATE 3, 50: PRINT "AnyDoubleClick : "; AnyDoubleClick
LOCATE 4, 50: PRINT "Click : "; Click ' default left click (same as LeftClick)
LOCATE 5, 50: PRINT "DoubleClick : "; DoubleClick ' default left double click (same as LeftDoubleClick)
LOCATE 6, 50: PRINT "LeftClick : "; LeftClick
LOCATE 7, 50: PRINT "MiddleClick : "; MiddleClick
LOCATE 8, 50: PRINT "RightClick : "; RightClick
LOCATE 9, 50: PRINT "LeftDoubleClick : "; LeftDoubleClick
LOCATE 10, 50: PRINT "MiddleDoubleClick: "; MiddleDoubleClick
LOCATE 11, 50: PRINT "RightDoubleClick : "; RightDoubleClick
LOCATE 12, 50: PRINT "AnyHold : "; AnyHold
LOCATE 13, 50: PRINT "ClickAndHold : "; ClickAndHold ' default left click and hold (same as LeftHold)
LOCATE 14, 50: PRINT "LeftHold : "; LeftHold
LOCATE 15, 50: PRINT "MiddleHold : "; MiddleHold
LOCATE 16, 50: PRINT "RightHold : "; RightHold
LOCATE 17, 50: PRINT "MouseAngle : "; MouseAngle
LOCATE 18, 50: PRINT "MouseVectorX : "; MouseVectorX
LOCATE 19, 50: PRINT "MouseVectorY : "; MouseVectorY
LOCATE 20, 50: PRINT "MouseX : "; MouseX
LOCATE 21, 50: PRINT "MouseY : "; MouseY
LOCATE 22, 50: PRINT "MousePreviousX : "; MousePreviousX
LOCATE 23, 50: PRINT "MousePreviousY : "; MousePreviousY
LOCATE 24, 50: PRINT "MouseWheel : "; MouseWheel
LOCATE 25, 50: PRINT "MouseSpeed : "; MouseSpeed
LOCATE 26, 50: PRINT "MousePointer : "; MousePointer;
SELECT CASE MousePointer
CASE 0: PRINT "Normal Select"
CASE 1: PRINT "Help Select"
CASE 2: PRINT "Working in Background"
CASE 3: PRINT "Busy"
CASE 4: PRINT "Precision Select"
CASE 5: PRINT "Text Select"
CASE 6: PRINT "Handwriting"
CASE 7: PRINT "Unavailable"
CASE 8: PRINT "Vertical Resize"
CASE 9: PRINT "Horizontal Resize"
CASE 10: PRINT "Diagonal Resize 1"
CASE 11: PRINT "Diagonal Resize 2"
CASE 12: PRINT "Move"
CASE 13: PRINT "Alternate Select"
CASE 14: PRINT "Link Select"
END SELECT
IF MouseHovering(0) THEN
LOCATE 27, 50: PRINT "MouseHovering : Zone"; MouseHovering(0)
ELSE
LOCATE 27, 50: PRINT "MouseHovering : Not hovering"
END IF
IF MouseTrapped(0) THEN
LOCATE 28, 50: PRINT "MouseTrapped : Zone"; MouseTrapped(0)
ELSE
LOCATE 28, 50: PRINT "MouseTrapped : Not trapped"
END IF
LOCATE 30, 50: PRINT "- Move mouse pointer to select zone area."
LOCATE 31, 50: PRINT "- Left click inside zone area to trap pointer."
LOCATE 32, 50: PRINT "- Right click to release pointer from zone."
LOCATE 33, 50: PRINT "- Rotate mouse wheel to select mouse pointer."
LOCATE 34, 50: PRINT "- ESC to exit."
LINE (600, 20)-(770, 200), _RGB32(255, 255, 255), BF ' icon viewing area
IF LeftClick AND MouseHovering(0) THEN TrapMouse MouseHovering(0) ' trap mouse in zone
IF MouseTrapped(0) AND RightClick THEN FreeMouse ' free trapped mouse
DrawMousePointer ' display mouse pointer
_DISPLAY ' udate screen with changes (no flicker)
LOOP UNTIL _KEYDOWN(27) ' leave when ESC pressed
SYSTEM ' return to OS
'+----------------------+
'| End demo use of code | <<--------------------------------------------------------------------------------------------------------------------------
'+----------------------+
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB UpdateMouse () ' UpdateMouse |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Updates the mouse properties. |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
SHARED Zone() AS TYPE_ZONE ' need access to mouse zones
DIM z AS INTEGER ' zone counter
Mouse.Wheel = 0 ' reset mouse wheel value
WHILE _MOUSEINPUT ' while mouse input exists
Mouse.Wheel = Mouse.Wheel + _MOUSEWHEEL ' get all cumulative wheel updates
WEND
CheckMouseButton Mouse.Left, _MOUSEBUTTON(1) ' update status of mouse buttons
CheckMouseButton Mouse.Right, _MOUSEBUTTON(2)
CheckMouseButton Mouse.Middle, _MOUSEBUTTON(3)
Mouse.Previous.x = Mouse.Location.x ' record previous mouse location
Mouse.Previous.y = Mouse.Location.y
Mouse.Location.x = _MOUSEX ' record current mouse location
Mouse.Location.y = _MOUSEY
IF UBOUND(Zone) THEN ' are any mouse zones defined?
IF Mouse.ZoneTrap THEN ' yes, is mouse trapped in a zone?
IF Mouse.Location.x < Mouse.Area.Min.x THEN Mouse.Location.x = Mouse.Area.Min.x ' yes, confine mouse to zone area
IF Mouse.Location.x > Mouse.Area.Max.x THEN Mouse.Location.x = Mouse.Area.Max.x
IF Mouse.Location.y < Mouse.Area.Min.y THEN Mouse.Location.y = Mouse.Area.Min.y
IF Mouse.Location.y > Mouse.Area.Max.y THEN Mouse.Location.y = Mouse.Area.Max.y
_MOUSEMOVE Mouse.Location.x, Mouse.Location.y ' force mouse to any updated coordinates
ELSE ' no, mouse is free
Mouse.Hovering = 0 ' assume mouse is not hovering a zone
z = 0 ' reset zone counter
DO ' cycle through zones
z = z + 1 ' increment zone counter
IF MouseZone(z) THEN Mouse.Hovering = z ' if mouse interacting with zone then record it hovering
LOOP UNTIL z = UBOUND(Zone) OR Mouse.Hovering ' leave when all zones checked or mouse is hovering
END IF
END IF
Mouse.Vector.x = Mouse.Location.x - Mouse.Previous.x ' calculate mouse vector movement from last position
Mouse.Vector.y = Mouse.Location.y - Mouse.Previous.y
Mouse.Degree = Vector2Degree(Mouse.Vector) ' calculate mouse degree movement from last position
Normalize Mouse.Vector, Mouse.Normal ' calculate normalized vector quantities
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB CheckMouseButton (Button AS TYPE_MOUSEBUTTON, Pressed AS INTEGER) ' CheckMouseButton |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Checks a mouse button for hold, click, and double click conditions and sets the appropriate mouse properties. This subroutine uses TIMER |
'| to determine double click intervals therefore it is independent of any FPS limit set by _LIMIT. However, this subroutine should be called at |
'| least 15 times per second for best results. |
'| |
'| Button - the mouse button UDT to check (Note: values are changed and passed back) |
'| Pressed - the related _MOUSEBUTTON() status |
'\_______________________________________________________________________________________________________________________________________________/
Button.Clicked = 0 ' reset button click flag
Button.DoubleClicked = 0 ' reset button double click flag
IF Pressed THEN ' is button pressed?
Button.Held = -1 ' yes, button is held down
ELSEIF Button.Held THEN ' no, was button previously down?
Button.Held = 0 ' yes, no longer being held
Button.Clicked = -1 ' button was single clicked
IF Button.DCTimer = 0 THEN ' first click of a possible double click?
Button.DCTimer = TIMER(.001) + Button.DCTime ' yes, set future double click time
ELSEIF TIMER(.001) <= Button.DCTimer THEN ' no, was second click within double click time?
Button.DoubleClicked = -1 ' yes, button was double clicked
Button.Clicked = 0 ' not a single click
Button.DCTimer = 0 ' reset double click timer
END IF
ELSEIF Button.DCTimer THEN ' no, is double click timer set?
IF TIMER(.001) > Button.DCTimer THEN ' yes, has time been exceeded for a double click?
Button.DCTimer = 0 ' yes, reset double click timer
END IF
END IF
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB DrawMousePointer () ' DrawMousePointer |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Draws the mouse pointer at the current mouse coordinates. |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
_PUTIMAGE (MouseX - Mouse.Pointer.Offset.x, MouseY - Mouse.Pointer.Offset.y), Mouse.Pointer.Image ' draw the pointer
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB SetMousePointer (p AS INTEGER) ' SetMousePointer |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Set the mouse pointer (0 to 14) |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
SHARED Pointer() AS TYPE_POINTER ' need access to pointer images
IF p < 0 THEN p = 14 ELSE IF p > 14 THEN p = 0 ' keep mouse pointer within limits
Mouse.Pointer = Pointer(p) ' set mouse pointer
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB SetLeftDoubleClickTime (dc AS SINGLE) ' SetLeftDoubleClickTime |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Sets the maximum time delay between two left button clicks to be considered a double click. |
'| |
'| dc - the time between two left clicks |
'| |
'| NOTE: dc is given in milliseconds, therefore a value such as .3 = 300 milliseconds or approximately 1/3rd of a second. |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
Mouse.Left.DCTime = dc ' record left button double click time
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB SetMiddleDoubleClickTime (dc AS SINGLE) ' SetMiddleDoubleClickTime |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Sets the maximum time delay between two middle button clicks to be considered a double click. |
'| |
'| dc - the time between two middle clicks |
'| |
'| NOTE: dc is given in milliseconds, therefore a value such as .3 = 300 milliseconds or approximately 1/3rd of a second. |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
Mouse.Middle.DCTime = dc ' record middle button double click time
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB SetRightDoubleClickTime (dc AS SINGLE) ' SetRightDoubleClickTime |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Sets the maximum time delay between two right button clicks to be considered a double click. |
'| |
'| dc - the time between two right clicks |
'| |
'| NOTE: dc is given in milliseconds, therefore a value such as .3 = 300 milliseconds or approximately 1/3rd of a second. |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
Mouse.Right.DCTime = dc ' record right button double click time
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB Normalize (vin AS TYPE_VECTOR, vout AS TYPE_VECTOR) ' Normalize |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Normalizes a vector passed in (0 to 1 for both quantities) and passes the result back. |
'| |
'| vin - the vector quantity pair to normalize |
'| vout - the normalized vector quantity pair result |
'\_______________________________________________________________________________________________________________________________________________/
DIM VectorLength AS SINGLE ' vector length (hypotenuse)
VectorLength = _HYPOT(vin.x, vin.y) ' calculate vector length
vout.x = vin.x / VectorLength ' normalize x quantity and pass back
vout.y = vin.y / VectorLength ' normalize y quantity and pass back
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
FUNCTION Vector2Degree (v AS TYPE_VECTOR) ' Vector2Degree |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Converts a vector quantity pair to a degree heading (0 to 359) |
'| |
'| Degree = Vector2Degree(Vector) |
'| |
'| v - the vector quantity pair |
'| .x = x quantity |
'| .y = y quantity |
'| |
'| Returns an integer degree value from 0 to 359 |
'\_______________________________________________________________________________________________________________________________________________/
DIM v2d AS SINGLE ' vector converted to degree
IF v.x = 0 AND v.y = 0 THEN ' vector passed in?
Vector2Degree = 0 ' no, return no degree
ELSEIF v.x = 0 THEN ' horizontal direction?
IF v.y > 0 THEN ' no, vertical downward direction?
Vector2Degree = 180 ' yes, must be 180 degrees
ELSEIF v.y < 0 THEN ' vertical upward direction?
Vector2Degree = 0 ' yes, must be 0 degrees
ELSE ' no, no vertical direction
Vector2Degree = 0 ' return no degree
END IF
ELSEIF v.y = 0 THEN ' no, vertical direction?
IF v.x > 0 THEN ' no, right horizontal direction?
Vector2Degree = 90 ' yes, must be 90 degrees
ELSEIF v.x < 0 THEN ' left horizontal direction?
Vector2Degree = 270 ' yes, must be 270 degrees
ELSE ' no, no horizontal direction
Vector2Degree = 0 ' return no degree
END IF
ELSE ' no, horizontal and vertical direction
v2d = _R2D(_ATAN2(v.y, v.x)) + 90 ' calculate radian converted to degree (rotated 90 for 0 degrees up)
IF v.x < 0 AND v.y < 0 THEN v2d = v2d + 360 ' add 360 if in 4th quadrant
Vector2Degree = INT(v2d) ' return degree
END IF
END FUNCTION
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB HideZone (z AS INTEGER) ' HideZone |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Hide a zone from being detected by the mouse pointer. |
'| |
'| z - the zone handle to hide |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Zone() AS TYPE_ZONE ' need access to mouse zones
Zone(z).Active = 0 ' hide zone from mouse
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB ShowZone (z AS INTEGER) ' ShowZone |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Reveal a previously hidden zone from the mouse pointer. |
'| |
'| z - the zone handle to reveal |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Zone() AS TYPE_ZONE ' need access to mouse zones
Zone(z).Active = -1 ' reveal zone to mouse
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB DrawBorder (z AS INTEGER) ' DrawBorder |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Draws a border around a zone area depecting the current state: |
'| Bright white - mouse is trapped in this zone |
'| White - mouse is hovering over this zone |
'| Gray - mouse has no interation with this zone |
'| |
'| z - The zone to draw a border around |
'| Supply the value of 0 to have borders drawn around all zones |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Zone() AS TYPE_ZONE ' need access to mouse zones
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
STATIC Colour(2) AS _UNSIGNED LONG ' border colors
DIM c AS INTEGER ' zone counter (start of count)
DIM Finish AS INTEGER ' end of zone counter
DIM Border AS INTEGER ' border color
IF UBOUND(Zone) = 0 OR z > UBOUND(Zone) THEN EXIT SUB ' leave if no defined zone areas
IF NOT Colour(0) THEN ' set border colors if not set yet
Colour(0) = _RGB32(127, 127, 127) ' not hovering (gray)
Colour(1) = _RGB32(192, 192, 192) ' hovering (white)
Colour(2) = _RGB32(255, 255, 255) ' trapped (bright white)
END IF
IF z = 0 THEN ' draw borders around all zones?
c = 0 ' yes, start at the beginning of zone array
Finish = UBOUND(Zone) ' finish at the end of the zone array
ELSE ' no, just a single zone
c = z - 1 ' start at the individual zone in array
Finish = z ' finish at the individual zone in array
END IF
DO ' cycle through chosen zone(s)
c = c + 1 ' increment zone counter
IF Zone(c).Active THEN ' is tis zone active?
Border = 0 ' yes, assume no interaction with zone
IF MouseHovering(c) THEN Border = 1 ' white border if mouse is hovering this zone
IF MouseTrapped(c) THEN Border = 2 ' bright white border if mouse is trapped in this zone
LINE (Zone(c).Area.Min.x, Zone(c).Area.Min.y)-(Zone(c).Area.Max.x, Zone(c).Area.Max.y), Colour(Border), B ' draw border
END IF
LOOP UNTIL c = Finish ' leave when zone(s) processed
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
FUNCTION MouseHovering (z AS INTEGER) ' MouseHovering |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Report mouse hovering status over a zone(s) |
'| |
'| z - the zone's handle to check for a hovering mouse (>0) |
'| supplying a value of 0 will simply return the zone handle where the mouse is hovering (0) |
'| Returns -1 (TRUE) if the mouse is hovering on the requested zone (-1) |
'| Returns a zone handle value if the zone requested is 0 and the mouse is hovering somewhere (>=0) |
'| Returns 0 (FALSE) if the mouse is not hovering in either scenario (0) |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Zone() AS TYPE_ZONE ' need access to mouse zones
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
MouseHovering = 0 ' assume mouse is not hovering (0 FALSE return)
IF Mouse.Hovering THEN ' is the mouse hovering over a zone?
IF z > 0 THEN ' yes, was a zone requested? (>0)
IF z = Mouse.Hovering THEN ' yes, is mouse hovering over the zone requested?
MouseHovering = z ' yes, report that mouse is hovering over requested zone (-1 TRUE return)
END IF
ELSE ' no, a zone was not requested
MouseHovering = Mouse.Hovering ' report any zone handle the mouse may be hovering over (>=0 TRUE or FALSE return)
END IF
END IF
END FUNCTION
' ______________________________________________________________________________________________________________________________________________
'/ \
FUNCTION MouseZone (z AS INTEGER) ' MouseZone |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Report interaction status of mouse and zone area |
'| |
'| z - the zone's handle |
'| Returns -1 (TRUE) if interaction, 0 (FALSE) otherwise |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Zone() AS TYPE_ZONE ' need access to mouse zones
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
DIM Trapped AS INTEGER ' mouse trapped status
IF NOT Zone(z).Active THEN EXIT FUNCTION ' leave is zone is inactive
MouseZone = 0 ' assume mouse not interacting with zone (0 FALSE return)
Trapped = MouseTrapped(0) ' record zone mouse may be trapped in
IF Trapped THEN ' is mouse trapped in a zone?
IF z = Trapped THEN ' yes, is it this zone?
MouseZone = -1 ' yes, report the only interaction that can happen (-1 TRUE return)
END IF
ELSE ' no, mouse if currently free
IF MouseHover(Zone(z).Area) THEN ' is mouse interacting with this zone?
MouseZone = -1 ' yes, report that mouse is in this zone (-1 TRUE return)
END IF
END IF
END FUNCTION
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB TrapMouse (z AS INTEGER) ' TrapMouse |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Trap mouse within a zone's area |
'| |
'| z - the handle of the zone to trap mouse in |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Zone() AS TYPE_ZONE ' need access to mouse zones
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
IF NOT Zone(z).Active THEN EXIT SUB ' can't trap mouse in inactive zone
Mouse.Area = Zone(z).Area ' define trapped area
Mouse.ZoneTrap = z ' mouse trapped in this zone (>0)
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB FreeMouse () ' FreeMouse |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Releases a trapped mouse. |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
Mouse.ZoneTrap = 0
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
FUNCTION MouseTrapped (z AS INTEGER) ' MouseTrapped |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Report mouse trapped status |
'| |
'| z - the zone's handle to check for a trapped mouse (>0) |
'| supplying a value of 0 will simply return the zone handle where the mouse is trapped (0) |
'| Returns -1 (TRUE) if the mouse is trapped in the requested zone (-1) |
'| Returns a zone handle value if the zone requested is 0 and the mouse is trapped somewhere (>=0) |
'| Returns 0 (FALSE) if the mouse is not trapped in either scenario (0) |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Zone() AS TYPE_ZONE ' need access to mouse zones
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
MouseTrapped = 0 ' assume mouse is not trapped (0 FALSE return)
IF Mouse.ZoneTrap THEN ' is the mouse trapped in a zone?
IF z > 0 THEN ' yes, was a zone requested? (>0)
IF z = Mouse.ZoneTrap THEN ' yes, is mouse trapped in zone requested?
MouseTrapped = -1 ' yes, report that mouse is trapped in requested zone (-1 TRUE return)
END IF
ELSE ' no, a zone was not requested (0)
MouseTrapped = Mouse.ZoneTrap ' report any zone handle the mouse may be trapped in (>=0 TRUE or FALSE return)
END IF
END IF
END FUNCTION
' ______________________________________________________________________________________________________________________________________________
'/ \
FUNCTION MouseHover (Area AS TYPE_AREA) ' MouseHover |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Returns a value of 1 if the mouse is hovering over the given area, 0 otherwise |
'| |
'| Area = the rectangular area |
'\_______________________________________________________________________________________________________________________________________________/
MouseHover = 0 ' assume mouse not hovering over area
WHILE _MOUSEINPUT: WEND ' get latest mouse updates
IF _MOUSEX >= Area.Min.x THEN ' is mouse pointer currently within area limits?
IF _MOUSEX <= Area.Max.x THEN
IF _MOUSEY >= Area.Min.y THEN
IF _MOUSEY <= Area.Max.y THEN
MouseHover = 1 ' yes, report that mouse is hovering this area
END IF
END IF
END IF
END IF
END FUNCTION
' ______________________________________________________________________________________________________________________________________________
'/ \
FUNCTION DefineMouseZone (x1 AS INTEGER, y1 AS INTEGER, w AS INTEGER, h AS INTEGER, Active AS INTEGER) ' DefineMouseZone |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Defines mouse zones within the main screen |
'| |
'| x1,y1 - upper left coordinate of zone area |
'| w - width of zone area |
'| h - height of zone area |
'| Active - mouse can see zone area (t/f) |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Zone() AS TYPE_ZONE ' need access to zone areas
REDIM _PRESERVE Zone(UBOUND(Zone) + 1) AS TYPE_ZONE ' increase array size
Zone(UBOUND(Zone)).Area.Min.x = x1 ' set new zone area coordinates
Zone(UBOUND(Zone)).Area.Max.x = x1 + w - 1
Zone(UBOUND(Zone)).Area.Min.y = y1
Zone(UBOUND(Zone)).Area.Max.y = y1 + h - 1
Zone(UBOUND(Zone)).Active = Active ' set active status
DefineMouseZone = UBOUND(Zone) ' return handle of zone area
END FUNCTION
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB MakePointer (p AS INTEGER, c AS STRING, d AS TYPE_VECTOR, Offset AS TYPE_VECTOR) ' MakePointer |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Used by the Initialize() subroutine to create mouse pointers. |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Pointer() AS TYPE_POINTER ' need access to pointer images
DIM clr(2) AS _UNSIGNED LONG ' colors used to draw pointers
DIM x AS INTEGER ' horizontal counter
DIM y AS INTEGER ' vertical counter
DIM Cpos AS INTEGER ' character position counter within string
DIM ch AS STRING * 1 ' current character within string
DIM Odest AS LONG ' calling destination
Odest = _DEST ' save calling destination
clr(0) = _RGB32(0, 0, 0) ' set colors
clr(1) = _RGB32(255, 255, 255)
clr(2) = _RGB32(43, 47, 55)
Pointer(p).Value = p ' record pointer handle
Pointer(p).Image = _NEWIMAGE(d.x, d.y, 32) ' create image canvas for pointer
Pointer(p).Offset = Offset ' record pointer offset values
_DEST Pointer(p).Image ' draw on pointer image
Cpos = 0 ' reset character position counter
FOR y = 0 TO d.y - 1 ' cycle through vertical pixels
FOR x = 0 TO d.x - 1 ' cycle through horizontal pixels
Cpos = Cpos + 1 ' increment character position counter
ch = MID$(c, Cpos, 1) ' get character from within string
IF ch <> " " THEN PSET (x, y), clr(VAL(ch)) ' draw pixel if one exists
NEXT x
NEXT y
_DEST Odest ' restore calling destination
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
SUB Initialize () ' Initialize |
' __________________________________________________________________________________________________________________________________________|____
'/ \
'| Draw the pointer icons and initialize mouse variables. |
'\_______________________________________________________________________________________________________________________________________________/
SHARED Mouse AS TYPE_MOUSE ' need access to mouse properties
SHARED Pointer() AS TYPE_POINTER ' need access to pointer images
DIM c(14) AS STRING ' ASCII representation of pointer image
DIM d(14) AS TYPE_VECTOR ' pointer dimensions
DIM o(14) AS TYPE_VECTOR ' pointer image offset from mousex and mousey
DIM p AS INTEGER ' pointer counter
'---------------------------- ---------------------------- -------------------------------------- --------------------------------------
' Busy 13x22 Normal Select 12x21 Working in Background 22x21 Help Select 22x19
'---------------------------- ---------------------------- -------------------------------------- --------------------------------------
c(3) = c(3) + "0000000000000": c(0) = c(0) + "0 ": c(2) = c(2) + "0 ": c(1) = c(1) + "0 "
c(3) = c(3) + "0011111111100": c(0) = c(0) + "00 ": c(2) = c(2) + "00 0000000000": c(1) = c(1) + "00 1111111 "
c(3) = c(3) + "0000000000000": c(0) = c(0) + "010 ": c(2) = c(2) + "010 0011111100": c(1) = c(1) + "010 100000001 "
c(3) = c(3) + " 01111111110 ": c(0) = c(0) + "0110 ": c(2) = c(2) + "0110 0000000000": c(1) = c(1) + "0110 10001100001 "
c(3) = c(3) + " 01111111110 ": c(0) = c(0) + "01110 ": c(2) = c(2) + "01110 01111110 ": c(1) = c(1) + "01110 10001 100001"
c(3) = c(3) + " 01101010110 ": c(0) = c(0) + "011110 ": c(2) = c(2) + "011110 01111110 ": c(1) = c(1) + "011110 10001 100001"
c(3) = c(3) + " 01110101110 ": c(0) = c(0) + "0111110 ": c(2) = c(2) + "0111110 01110110 ": c(1) = c(1) + "0111110 10001 100001"
c(3) = c(3) + " 00111011100 ": c(0) = c(0) + "01111110 ": c(2) = c(2) + "01111110 00101100 ": c(1) = c(1) + "01111110 10001 10001 "
c(3) = c(3) + " 001111100 ": c(0) = c(0) + "011111110 ": c(2) = c(2) + "011111110 001100 ": c(1) = c(1) + "01111111011111 10001 "
c(3) = c(3) + " 0010100 ": c(0) = c(0) + "0111111110 ": c(2) = c(2) + "0111111110 0010 ": c(1) = c(1) + "0111111110 10001 "
c(3) = c(3) + " 00100 ": c(0) = c(0) + "01111111110 ": c(2) = c(2) + "01111111110 001100 ": c(1) = c(1) + "01111100000 10001 "
c(3) = c(3) + " 00100 ": c(0) = c(0) + "011111100000": c(2) = c(2) + "011111100000 00111100 ": c(1) = c(1) + "0110110 10001 "
c(3) = c(3) + " 0011100 ": c(0) = c(0) + "01110110 ": c(2) = c(2) + "01110110 01101110 ": c(1) = c(1) + "010 0110 10001 "
c(3) = c(3) + " 001101100 ": c(0) = c(0) + "01100110 ": c(2) = c(2) + "01100110 01010110 ": c(1) = c(1) + "00 0110 111 "
c(3) = c(3) + " 00111111100 ": c(0) = c(0) + "010 0110 ": c(2) = c(2) + "010 0110 00101010 ": c(1) = c(1) + "0 0110 10001 "
c(3) = c(3) + " 01111011110 ": c(0) = c(0) + "00 0110 ": c(2) = c(2) + "00 0110 0000000000": c(1) = c(1) + " 0110 1000001 "
c(3) = c(3) + " 01110101110 ": c(0) = c(0) + "0 0110 ": c(2) = c(2) + "0 0110 0011111100": c(1) = c(1) + " 0110 10001 "
c(3) = c(3) + " 01101010110 ": c(0) = c(0) + " 0110 ": c(2) = c(2) + " 0110 0000000000": c(1) = c(1) + " 0110 111 "
c(3) = c(3) + " 01010101010 ": c(0) = c(0) + " 0110 ": c(2) = c(2) + " 0110 ": c(1) = c(1) + " 00 "
c(3) = c(3) + "0000000000000": c(0) = c(0) + " 0110 ": c(2) = c(2) + " 0110 "
c(3) = c(3) + "0011111111100": c(0) = c(0) + " 00 ": c(2) = c(2) + " 00 "
c(3) = c(3) + "0000000000000"
'--------------------------------------- ---------------------------------------- ----------------------------------- ---------------------------------------
' Precision Select 24x24 Handwriting 24x24 Link Select 17x22 Move 21x21
'--------------------------------------- ---------------------------------------- ----------------------------------- ---------------------------------------
c(4) = c(4) + " 22 ": c(6) = c(6) + "11 ": c(14) = c(14) + " 00 ": c(12) = c(12) + " 1 "
c(4) = c(4) + " 22 ": c(6) = c(6) + "1011 ": c(14) = c(14) + " 0110 ": c(12) = c(12) + " 101 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 10011 ": c(14) = c(14) + " 0110 ": c(12) = c(12) + " 10001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 100001 ": c(14) = c(14) + " 0110 ": c(12) = c(12) + " 1000001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 100101 ": c(14) = c(14) + " 0110 ": c(12) = c(12) + " 100000001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1000101 ": c(14) = c(14) + " 011000 ": c(12) = c(12) + " 111101111 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1001101 ": c(14) = c(14) + " 011011000 ": c(12) = c(12) + " 11 101 11 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1001101 ": c(14) = c(14) + " 01101101100 ": c(12) = c(12) + " 101 101 101 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1001101 ": c(14) = c(14) + " 011011011010 ": c(12) = c(12) + " 1001 101 1001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1001101 ": c(14) = c(14) + "000 0110110110110": c(12) = c(12) + " 1000111110111110001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1001101 ": c(14) = c(14) + "01100111111110110": c(12) = c(12) + "100000000000000000001"
c(4) = c(4) + "222222222222222222222222": c(6) = c(6) + " 1001101 1 ": c(14) = c(14) + "01110111111111110": c(12) = c(12) + " 1000111110111110001 "
c(4) = c(4) + "222222222222222222222222": c(6) = c(6) + " 1001101101 ": c(14) = c(14) + " 0110111111111110": c(12) = c(12) + " 1001 101 1001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1010101001 ": c(14) = c(14) + " 010111111111110": c(12) = c(12) + " 101 101 101 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1000100001 ": c(14) = c(14) + " 011111111111110": c(12) = c(12) + " 11 101 11 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1000101001 ": c(14) = c(14) + " 01111111111110": c(12) = c(12) + " 111101111 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1000101001 ": c(14) = c(14) + " 0111111111110 ": c(12) = c(12) + " 100000001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1000101001": c(14) = c(14) + " 011111111110 ": c(12) = c(12) + " 1000001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 100010101": c(14) = c(14) + " 011111111110 ": c(12) = c(12) + " 10001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 10001001": c(14) = c(14) + " 0111111110 ": c(12) = c(12) + " 101 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1000101": c(14) = c(14) + " 0111111110 ": c(12) = c(12) + " 1 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 100001": c(14) = c(14) + " 0000000000 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 1001 "
c(4) = c(4) + " 22 ": c(6) = c(6) + " 11 "
'------------------------ ------------------------------------ --------------------------- -----------------------
' Vertical Resize 9x21 Unavailable 20x20 Alternate Select 9x19 Text Select 7x16
'------------------------ ------------------------------------ --------------------------- -----------------------
c(8) = c(8) + " 1 ": c(7) = c(7) + " 111111 ": c(13) = c(13) + " 1 ": c(5) = c(5) + "222 222"
c(8) = c(8) + " 101 ": c(7) = c(7) + " 1100000011 ": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 10001 ": c(7) = c(7) + " 100000000001 ": c(13) = c(13) + " 10001 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 1000001 ": c(7) = c(7) + " 10000111100001 ": c(13) = c(13) + " 1000001 ": c(5) = c(5) + " 2 "
c(8) = c(8) + "100000001": c(7) = c(7) + " 100011 110001 ": c(13) = c(13) + "100000001": c(5) = c(5) + " 2 "
c(8) = c(8) + "111101111": c(7) = c(7) + " 1000001 10001 ": c(13) = c(13) + "111101111": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + " 10010001 1001 ": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + "1000110001 10001": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + "1001 10001 1001": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + "1001 10001 1001": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + "1001 10001 1001": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + "1001 10001 1001": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + "10001 1000110001": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + " 1001 10001001 ": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + " 101 ": c(7) = c(7) + " 10001 1000001 ": c(13) = c(13) + " 101 ": c(5) = c(5) + " 2 "
c(8) = c(8) + "111101111": c(7) = c(7) + " 100011 110001 ": c(13) = c(13) + " 101 ": c(5) = c(5) + "222 222"
c(8) = c(8) + "100000001": c(7) = c(7) + " 10000111100001 ": c(13) = c(13) + " 101 "
c(8) = c(8) + " 1000001 ": c(7) = c(7) + " 100000000001 ": c(13) = c(13) + " 101 "
c(8) = c(8) + " 10001 ": c(7) = c(7) + " 1100000011 ": c(13) = c(13) + " 111 "
c(8) = c(8) + " 101 ": c(7) = c(7) + " 111111 "
c(8) = c(8) + " 1 "
'-------------------------------- --------------------------------- -------------------------------------
' Diagonal Resize 2 15x15 Diagonal Resize 1 15x15 Horizontal Resize 21x9
'-------------------------------- --------------------------------- -------------------------------------
c(11) = c(11) + " 1111111": c(10) = c(10) + "1111111 ": c(9) = c(9) + " 11 11 "
c(11) = c(11) + " 1000001": c(10) = c(10) + "1000001 ": c(9) = c(9) + " 101 101 "
c(11) = c(11) + " 100001": c(10) = c(10) + "100001 ": c(9) = c(9) + " 1001 1001 "
c(11) = c(11) + " 10001": c(10) = c(10) + "10001 ": c(9) = c(9) + " 1000111111111110001 "
c(11) = c(11) + " 101001": c(10) = c(10) + "100101 ": c(9) = c(9) + "100000000000000000001"
c(11) = c(11) + " 101 101": c(10) = c(10) + "101 101 ": c(9) = c(9) + " 1000111111111110001 "
c(11) = c(11) + " 101 11": c(10) = c(10) + "11 101 ": c(9) = c(9) + " 1001 1001 "
c(11) = c(11) + " 101 ": c(10) = c(10) + " 101 ": c(9) = c(9) + " 101 101 "
c(11) = c(11) + "11 101 ": c(10) = c(10) + " 101 11": c(9) = c(9) + " 11 11 "
c(11) = c(11) + "101 101 ": c(10) = c(10) + " 101 101"
c(11) = c(11) + "100101 ": c(10) = c(10) + " 101001"
c(11) = c(11) + "10001 ": c(10) = c(10) + " 10001"
c(11) = c(11) + "100001 ": c(10) = c(10) + " 100001"
c(11) = c(11) + "1000001 ": c(10) = c(10) + " 1000001"
c(11) = c(11) + "1111111 ": c(10) = c(10) + " 1111111"
d(0).x = 12: d(0).y = 21: o(0).x = 0: o(0).y = 0 ' Normal Select Mouse pointer widths and heights ( d().x and d().y )
d(1).x = 22: d(1).y = 19: o(1).x = 0: o(1).y = 0 ' Help Select
d(2).x = 22: d(2).y = 21: o(2).x = 0: o(2).y = 0 ' Working in Background Mouse pointer offsets ( o().x and o().y )
d(3).x = 13: d(3).y = 22: o(3).x = 6: o(3).y = 11 ' Busy
d(4).x = 24: d(4).y = 24: o(4).x = 12: o(4).y = 12 ' Precision Select
d(5).x = 7: d(5).y = 16: o(5).x = 3: o(5).y = 8 ' Text Select
d(6).x = 24: d(6).y = 24: o(6).x = 0: o(6).y = 0 ' Handwriting
d(7).x = 20: d(7).y = 20: o(7).x = 10: o(7).y = 10 ' Unavailable
d(8).x = 9: d(8).y = 21: o(8).x = 4: o(8).y = 10 ' Vertical Resize
d(9).x = 21: d(9).y = 9: o(9).x = 10: o(9).y = 4 ' Horizontal Resize
d(10).x = 15: d(10).y = 15: o(10).x = 7: o(10).y = 7 ' Diagonal Resize 1
d(11).x = 15: d(11).y = 15: o(11).x = 7: o(11).y = 7 ' Diagonal Resize 2
d(12).x = 21: d(12).y = 21: o(12).x = 10: o(12).y = 10 ' Move
d(13).x = 9: d(13).y = 19: o(13).x = 4: o(13).y = 0 ' Alternate Select
d(14).x = 17: d(14).y = 22: o(14).x = 5: o(14).y = 0 ' Link Select
FOR p = 0 TO 14 ' create mouse pointer images
MakePointer p, c(p), d(p), o(p) ' value, string representation, dimensions, offset
NEXT p
Mouse.Left.DCTime = .3 ' set button double click times
Mouse.Right.DCTime = .3
Mouse.Middle.DCTime = .3
Mouse.Pointer = Pointer(0) ' default pointer (normal select)
END SUB
' ______________________________________________________________________________________________________________________________________________
'/ \
'| Mouse property reporting functions |
'|______________________________________________________________________________________________________________________________________________|____
'| \
'| The following functions return the various mouse properties available. |
'\___________________________________________________________________________________________________________________________________________________/
FUNCTION MousePointer () ' report the current mouse pointer number
SHARED Mouse AS TYPE_MOUSE
MousePointer = Mouse.Pointer.Value
END FUNCTION
FUNCTION MouseSpeed () ' report speed of mouse as it moves from one position to the next
SHARED Mouse AS TYPE_MOUSE
MouseSpeed = INT(_HYPOT(Mouse.Vector.x, Mouse.Vector.y))
END FUNCTION
FUNCTION MouseWheel () ' report cumulative wheel value between updates
SHARED Mouse AS TYPE_MOUSE
MouseWheel = Mouse.Wheel
END FUNCTION
FUNCTION MouseVectorX () ' report the x vector quantity change from one position to the next
SHARED Mouse AS TYPE_MOUSE
MouseVectorX = Mouse.Vector.x
END FUNCTION
FUNCTION MouseVectorY () ' report the y vector quantity change from one position to the next
SHARED Mouse AS TYPE_MOUSE
MouseVectorY = Mouse.Vector.y
END FUNCTION
FUNCTION MouseNormalX () ' report the normalized x vector quantity change from one position to the next
SHARED Mouse AS TYPE_MOUSE
MouseNormalX = Mouse.Normal.x
END FUNCTION
FUNCTION MouseNormalY () ' report the normalized y vector quantity change from one position to the next
SHARED Mouse AS TYPE_MOUSE
MouseNormalY = Mouse.Normal.y
END FUNCTION
FUNCTION AnyClick () ' report any button that has been clicked
AnyClick = LeftClick OR MiddleClick OR RightClick
END FUNCTION
FUNCTION AnyDoubleClick () ' report any button that has been double clicked
AnyDoubleClick = LeftDoubleClick OR MiddleDoubleClick OR RightDoubleClick
END FUNCTION
FUNCTION Click () ' report if the left button has been clicked
Click = LeftClick
END FUNCTION
FUNCTION DoubleClick () ' report if the left button has been double clicked
DoubleClick = LeftDoubleClick
END FUNCTION
FUNCTION LeftClick () ' report if the left button has been clicked
SHARED Mouse AS TYPE_MOUSE
LeftClick = Mouse.Left.Clicked
END FUNCTION
FUNCTION LeftDoubleClick () ' report if the left button has been double clicked
SHARED Mouse AS TYPE_MOUSE
LeftDoubleClick = Mouse.Left.DoubleClicked
END FUNCTION
FUNCTION RightClick () ' report if the right button has been clicked
SHARED Mouse AS TYPE_MOUSE
RightClick = Mouse.Right.Clicked
END FUNCTION
FUNCTION RightDoubleClick () ' report if the right button has been double clicked
SHARED Mouse AS TYPE_MOUSE
RightDoubleClick = Mouse.Right.DoubleClicked
END FUNCTION
FUNCTION MiddleClick () ' report if the middle button has been clicked
SHARED Mouse AS TYPE_MOUSE
MiddleClick = Mouse.Middle.Clicked
END FUNCTION
FUNCTION MiddleDoubleClick () ' report if the middle button has been double clicked
SHARED Mouse AS TYPE_MOUSE
MiddleDoubleClick = Mouse.Middle.DoubleClicked
END FUNCTION
FUNCTION MouseAngle () ' report the degree angle the mouse moved in from one position to the next
SHARED Mouse AS TYPE_MOUSE
MouseAngle = Mouse.Degree
END FUNCTION
FUNCTION ClickAndHold () ' report if the left button is being held down
ClickAndHold = LeftHold
END FUNCTION
FUNCTION AnyHold () ' report if any button is being held down
SHARED Mouse AS TYPE_MOUSE
AnyHold = LeftHold OR MiddleHold OR RightHold
END FUNCTION
FUNCTION LeftHold () ' report if the left button is being held down
SHARED Mouse AS TYPE_MOUSE
LeftHold = Mouse.Left.Held
END FUNCTION
FUNCTION MiddleHold () ' report if the middle button is being held down
SHARED Mouse AS TYPE_MOUSE
MiddleHold = Mouse.Middle.Held
END FUNCTION
FUNCTION RightHold () ' report if the right button is being held down
SHARED Mouse AS TYPE_MOUSE
RightHold = Mouse.Right.Held
END FUNCTION
FUNCTION MouseX () ' report the current x coordinate of the pointer
SHARED Mouse AS TYPE_MOUSE
MouseX = Mouse.Location.x
END FUNCTION
FUNCTION MouseY () ' report the current y coordinate of the pointer
SHARED Mouse AS TYPE_MOUSE
MouseY = Mouse.Location.y
END FUNCTION
FUNCTION MousePreviousX () ' report the previous x coodinate of the pointer
SHARED Mouse AS TYPE_MOUSE
MousePreviousX = Mouse.Previous.x
END FUNCTION
FUNCTION MousePreviousY () ' report the previous y coordinate of the pointer
SHARED Mouse AS TYPE_MOUSE
MousePreviousY = Mouse.Previous.y
END FUNCTION
' ______________________________________________________________________________________________________________________________________________
'/ \
'| Documentation Documentation |
'|______________________________________________________________________________________________________________________________________________|____
'| \
'| This set of functions and subroutines is used to track all mouse and mouse button activity and give the ability to report on the status of all |
'| that activity. This code also gives you the ability to set up predefined mouse zones that the mouse pointer can interact with and get trapped |
'| within. |
'|___________________________________________________________________________________________________________________________________________________|
'| |
'| ---------------- |
'| Basic Mouse Use: |
'| ---------------- |
'| |
'| The snippet of code below will give you access to the status of the mouse buttons and mouse pointer coordinate related functions. |
'| |
'| SCREEN _NEWIMAGE(640, 480, 32) ' these mouse routines only work in a graphics screen |
'| _MOUSEHIDE ' hide system mouse pointer |
'| Initialize ' initialize the mouse pointers and settings |
'| DO ' main program loop |
'| CLS |
'| _LIMIT 30 ' optional frames per second limit (keep at >=15 for best results) |
'| UpdateMouse ' update mouse values |
'| |
'| '+----------------+ |
'| '| Your code here | |
'| '+----------------+ |
'| |
'| DrawMousePointer ' draw the mouse pointer at the current x and y coordinates |
'| LOOP |
'|___________________________________________________________________________________________________________________________________________________|
'| |
'| --------------------- |
'| Basic Mouse Zone Use: |
'| --------------------- |
'| |
'| The snippet of code below will create a single mouse zone and give you access to the status of the mouse interacting with zone related functions. |
'| |
'| DIM Zone AS INTEGER ' create handle to hold mouse zone properties |
'| |
'| Zone = DefineMouseZone(10, 10, 100, 100, TRUE) ' create a mouse zone that is visible to the mouse |
'| |
'| SCREEN _NEWIMAGE(640, 480, 32) ' these mouse routines only work in a graphics screen |
'| _MOUSEHIDE ' hide system mouse pointer |
'| Initialize ' initialize the mouse pointers and settings |
'| DO ' main program loop |
'| CLS |
'| _LIMIT 30 ' optional frames per second limit (keep at >=15 for best results) |
'| UpdateMouse ' update mouse values |
'| |
'| '+----------------+ |
'| '| Your code here | |
'| '+----------------+ |
'| |
'| DrawBorder Zone ' draw a border around the mouse zone (optional) |
'| DrawMousePointer ' draw the mouse pointer at the current x and y coordinates |
'| LOOP |
'|___________________________________________________________________________________________________________________________________________________|
'| |
'| ---------------------------------------- |
'| Mouse related subroutines and functions: |
'| ---------------------------------------- |
'| |
'| UpdateMouse |
'| |
'| - Updates the mouse properties. Must be called at the beginning of the main program loop. |
'| |
'| DrawMousePointer |
'| |
'| - Draws the current mouse pointer to the current x,y coordinate of the mouse on screen. Use this subroutine in your main program loop after all |
'| other drawing to the screen has been done. |
'| |
'| SetMousePointer PointerValue |
'| |
'| - Sets the mouse pointer to one of 15 different mouse pointer icons. |
'| - PointerValue - can be any value from 0 to 14. |
'| |
'| Pointer = MousePointer |
'| |
'| - Returns the current icon pointer value. |
'| - Pointer - will contain a value from 0 to 14. |
'| |
'| SetLeftDoubleClickTime DCTime |
'| |
'| - Sets the maximum time interval between two left button clicks to be considered a double click. |
'| - The default time, as set by Initialize, is 300 milliseconds. |
'| - DCTime - the time in milliseconds (i.e. .3 = 300 Milliseconds or approximatly 1/3rd of a second) |
'| |
'| SetMiddleDoubleClickTime DCTime |
'| |
'| - Sets the maximum time interval between two middle button clicks to be considered a double click. |
'| - The default time, as set by Initialize, is 300 milliseconds. |
'| - DCTime - the time in milliseconds (i.e. .3 = 300 Milliseconds or approximatly 1/3rd of a second) |
'| |
'| SetRightDoubleClickTime DCTime |
'| |
'| - Sets the maximum time interval between two right button clicks to be considered a double click. |
'| - The default time, as set by Initialize, is 300 milliseconds. |
'| - DCTime - the time in milliseconds (i.e. .3 = 300 Milliseconds or approximatly 1/3rd of a second) |
'|___________________________________________________________________________________________________________________________________________________|
'| |
'| --------------------------------------------- |
'| Mouse zone related subroutines and functions: |
'| --------------------------------------------- |
'| |
'| DefineMouseZone x1, y1, Width, Height, Active |
'| |
'| - Creates an area on screen that the mouse will actively monitor for activity. |
'| - x1, y1 - the upper left corner of the area |
'| - Width - the width of the area |
'| - Height - the height of the area |
'| - Active - zone is visible to the mouse pointer (-1 (TRUE) or 0 (FALSE)) |
'| |
'| DrawBorder Zone |
'| |
'| - Draws a border around a visible (active) defined mouse zone. The border will change color according to mouse pointer activity: |
'| : Gray - no mouse pointer interaction. |
'| : White - mouse pointer is hovering over the mouse zone. |
'| : Bright White - mouse pointer is trapped within the mouse zone. |
'| - Zone - the mouse zone to draw a border around. |
'| - supplying a value of 0 (zero) will draw borders around all defined and visible mouse zones. |
'| |
'| Hovering = MouseHovering(Zone) |
'| |
'| - Returns the status of the mouse pointer hovering over a zone. |
'| - Zone - the mouse zone to check for the mouse pointer hovering over. |
'| - supplying a value of 0 (zero) will check all mouse zones for mouse pointer hovering. |
'| - Hovering - will return -1 (TRUE), 0 (FALSE), or a mouse zone handle depending on the setting of Zone. |
'| - -1 (TRUE) when the mouse pointer is hovering over the Zone specified. |
'| - 0 (FALSE) when the mouse is not hovering over the Zone specified. |
'| - a zone handle value if the value of 0 (zero) was passed in for Zone and the mouse is hovering a defined and visible mouse zone. |
'| - 0 (FALSE) if the value of 0 (zero) was passed in for Zone and the mouse is not hovering a defined and visible mouse zone. |
'| |
'| Trapped = MouseTrapped(Zone) |
'| |
'| - Returns the status of a mouse trapped within a zone. |
'| - Zone - the mouse zone to check for the mouse pointer trapped in. |
'| - supplying a value of 0 (zero) will check all mouse zones for a trapped mouse pointer. |
'| - Trapped - will return -1 (TRUE), 0 (FALSE), or a mouse zone handle depending on the setting of Zone. |
'| - -1 (TRUE) when the mouse pointer is trapped in the Zone specified. |
'| - 0 (FALSE) when the mouse pointer is not trapped within the Zone specified. |
'| - a zone handle value if the value of 0 (zero) was passed in for Zone and the mouse is trapped in a defined and visible mouse zone. |
'| - 0 (FALSE) if the value of 0 (zero) was passed in for Zone and the mouse is not trapped in a defined and visible mouse zone. |
'| |
'| Status = MouseZone(Zone) |
'| |
'| - Returns the status of any type of interaction with the mouse pointer an a defined visible zone. |
'| - Status - -1 (TRUE) if mouse pointer interaction with Zone, 0 (FALSE) otherwise. |
'| - Zone - the mouse to check for mouse pointer interation. |
'| |
'| HideZone Zone |
'| |
'| - Hides a zone from the moue pointer. |
'| - Zone - the zone to hide the mouse from. |
'| |
'| ShowZone Zone |
'| |
'| - Reveals a mouse zone previously hidden to the mouse pointer. |
'| - Zone - the zone to reveal to the mouse pointer. |
'| |
'| TrapMouse Zone |
'| |
'| - Traps a mouse pointer within the confines of a defined mouse zone. |
'| - Zone - the zone to trap the mouse pointer in. |
'| |
'| FreeMouse |
'| |
'| - Frees a trapped mouse from within any mouse zone. |
'|___________________________________________________________________________________________________________________________________________________|
'| |
'| --------------------------------------------------------------- |
'| The following functions return the status of the mouse buttons: |
'| --------------------------------------------------------------- |
'| |
'| AnyClick - returns -1 (TRUE) when the left, middle, or right button is clicked. |
'| AnyDoubleClick - returns -1 (TRUE) when the left, middle, or right button is double clicked. |
'| Click - returns -1 (TRUE) when the left button is clicked (same as LeftClick). |
'| DoubleClick - returns -1 (TRUE) when the left button is double clicked (same as LeftDoubleClick). |
'| LeftClick - returns -1 (TRUE) when the left button is clicked. |
'| LeftDoubleClick - returns -1 (TRUE) when the left button is double clicked. |
'| RightClick - returns -1 (TRUE) when the right button is clicked. |
'| RightDoubleClick - returns -1 (TRUE) when the right button is double clicked. |
'| MiddleClick - returns -1 (TRUE) when the middle button is clicked. |
'| MiddleDoubleClick - returns -1 (TRUE) when the middle button is double clicked. |
'| AnyHold - Returns -1 (TRUE) when the left, middle, or right button is held down. |
'| ClickAndHold - returns -1 (TRUE) when the left button is held down (same as LeftHold). |
'| LeftHold - returns -1 (TRUE) when the left button is held down. |
'| MiddleHold - returns -1 (TRUE) when the middle button is held down. |
'| RightHold - returns -1 (TRUE) when the right button is held down. |
'| MouseWheel - returns the cumulative result of mouse wheel turns from the previous mouse update to the current mouse update. |
'|___________________________________________________________________________________________________________________________________________________|
'| |
'| --------------------------------------------------------------------------- |
'| The following functions return the status of the mouse pointer coordinates: |
'| --------------------------------------------------------------------------- |
'| |
'| MouseX - the current x coordinate location of the mouse pointer. |
'| MouseY - the current y coordinate location of the mouse pointer. |
'| MousePreviousX - the x coordinate location of the mouse pointer during the previous mouse update. |
'| MousePreviousY - the y coordinate location of the mouse pointer during the previous mouse update. |
'| MouseVectorX - the x movement vector of the mouse pointer from the previous coordinate location to the current coordinate location. |
'| MouseVectorY - the y movement vector of the mouse pointer from the previous coordinate location to the current coordinate location. |
'| MouseNormalX - the normalized value of MouseVectorX (-1 to 1). |
'| MouseNormalY - the normalized value of MouseVectorY (-1 to 1). |
'| MouseAngle - the degree angle of mouse pointer movement from the previous coordinate location to the current coordinate location (0 to 359). |
'| MouseSpeed - the speed of mouse pointer movement from the previous coordinate location to the current coordinate location. |
'\___________________________________________________________________________________________________________________________________________________/