Quote: "And if you think of any other mouse commands I should add, let me know."
Since I will use your library I am going to lay out a plan of what mouse features I need. You can add these commands if you want, but unless you beat me to it, I will create them over time.
I am also taking the opportunity to think about this carefully because it is a good opportunity to wrap this topic up.
The library as it stands covers most typical game mouse commands; to be honest any more commands would be more of a convinience than a necessity, but for the few working on large games, there is that small percentange of end users who want to go extreme and then there is the latest gimmicks and technologies.
I'd say multi-button mouse events would be good to add.
Mouse button 4,5,6 etc ; although I can't seem to get DBPRO to detect my 5th button... It detects mouse button 4 in the 4th bit ( 8 ), but not button 5 ( 16 ).
The other things that are vital for most people is 1st mouse over events, 2nd dragging, and 3rd, mouse gestures.
Mouse over
Basic
Most mouse events require a clicking zone, and most DBP programmers would have to check what zones the mouse is over before firing a click event.
//============================================================
Function MouseClickedIn(x1,y1,x2,y2)
If WithinAreaValue(MouseX(),MouseY(),0,x2,y2,0)
ExitFunction 1
Endif
Endfunction 0
//========================================================
Function WithinAreaValue(x#,z#,x2#,y2#,w#,h#)
If Within(x#, x2#, x2#+w#)
If Within(y#, y2#, y2#+h#)
ExitFunction 1
Endif
Endif
Endfunction 0
//========================================================
Function WithinArea(x#,z#,a as AreaType)
If Within(x#, a.left#, a.right#)
If Within(y#, a.top#, a.bottom# )
ExitFunction 1
Endif
Endif
Endfunction 0
//========================================================
Function Within(v#,fMin#,fMax#)
If v# > fMax# Then ExitFunction 0
If v# < fMin# Then ExitFunction 0
Endfunction 1
Any additional features and alternatives of that shouldn't be a bad idea to throw in. Feel three to use that code if you need.
Intermediate
In intermediate projects, one would need to know how long the mouse over event occurs for and how long the mouse is idle for
If VecIsZero(MouseMove) ` Or simply check mousemovex() etc
If Timer() - MouseMovedTime > MouseIdleDelay
If MouseIsIdle = 0
// MLg("Mouse is idle")
Endif
MouseIsIdle = 1
Endif
Else
MouseMovedTime = Timer()
MouseIsIdle = 0
Endif
. Good example is renaming files with slow double click whilst keeping the mouse still. Or mouse hints, although some hints wouldn't need a delay or could simply transition if they did.
Another practical feature is storing the idle position, and use it to determine how far the mouse moved from the idle position. If the mouse moved by 1 or 2 pixels, it would be harsh to consider that a mouse move event in certain situations. Having a movement vector could allow one to determine whether the mouse moved enough to warrant taking a specific action; maybe even an idle threshold.
Having an event data UDT would be a good idea, something that supplies information about mouse movement; you never know what might come handy.
Advanced
For those few advanced projects out there; I really doubt there will be many guys making advanced projects, so the basics come first. However, us guys need to structure mouse over events into zones. We'd want to know what mouse over zone has the focus, is topmost and highest in priority (See dragging intermediate for an example).
Checking for a button click in an area and an object click in the same area at the same time for example is inevitable as it stands. If a UI zone covers an object zone, the UI zone would have the priority.
Dragging
Basic
I think most DBP users would have liked a drag function which returns a start location, current mouse location, release location and release button.
Intermediate
Similar to other mouse events, a zone, an area of influence would be taken into consideration. Anyone creating draggable windows and items would need to determine what list of zones the drag event started from, what zone/s the mouse is currently in whilst the button is held, and what zone/s the mouse release occured in. What is being dragged is the responsibility of another library, however it would be wise to store the zone ID/S in the event which could be used as an external pointer to the external item being dragged.
If any zone is under the mouse, we'd need a way to be aware of this in the form of a list. Matrix1 zones are a good example.
Advanced
For those few advanced projects that end up using this; I think again, we would need ordering of zones of influence. Whilst on the intermediate level, all zones are listed, on the advanced level, the zone of highest priority / topmost zone would need to be indicated somehow.
If the start drag zones are 1,2 and 3; if the topmost drag zone happens to be 3, then zone 3 is set as the primary drag zone; although 1 and 2 are were technically being dragged, the programmer could choose to refer to the primary zone, or perhaps the zones could be sorted in an ordered list.
Also, if the drag zones are 1,2 and 3; if the topmost zone is 3 but the zone with the highest priority is 1, then 1 is the primary / first drag zone. Where would this be useful? Modal UI, without having to remember the layering order of 100s of zones, simply raise priority to overshadow all underlying mouse zones.
Also, if the drop zone is 4, 5, and 6; the topmost or highest priorty drop zone would need to be determined.
Additionally, relationships between zones; returning if there is a drag drop event occuring in two zones in the same group, or that share a flag in a 32bit/64bit variable. So for example, the user cannot drag a button macro onto a character, or a game file onto an action button.
Gestures
Basic
Once gesture mode is switched on some how; dragging with a mouse / button down to the left, right, up or down could trigger a simple scroll / pan / rotate gesture UDT property for scroll, pan or rotate based elements. The difference between this and simply using the MouseMove functions is that there needs to be a minimum and maximum motion for the gesture to be detected.
Intermediate
I once was asked to make a martial arts game for someone where the character would perform certain moves using mouse gestures (might point this idea to
Dimis). I've lost the source code but what I think I did was record nodes during mouse movements after idle events, start from the first node once the motion stopped, then checked what primitive directions each node was facing and added each direction's name to a string
EG: "LEFT-UP-LEFT", or "UP-HOLD-DOWN-HOLD", or "LEFT-UP-UP-UP" for a long L shape or "DOWNLEFT-UPLEFT" for diagonal v motion
After a second the string use used as a bound command.
So, for tablet / laptop users, this stuff would be great. In fact I have a standard desktop mouse which can be programmed to perform different actions by gesturing in staight lines and L shapes.
Most 3D games don't support it, but its getting more popular, especially in the touch screen / netbook / tablet market. For each keyboard button and shortcut, multiply that by the amount of gestures you can do, gives you unlimited range of fast actions, which can be illustrated with on screen feedback.
Advanced
I don't have Windows 8 or a device that supports multiple drags at the same time. But I think I am way outnumbered. If you know how all of that stuff works, please do provide us with a helper library, perhaps as an addon to code for such systems.
Thanks for all the code you have already provided.