- Lua Game Development Cookbook
- Mário Ka?uba
- 180字
- 2021-07-16 13:23:09
Using the absolute mouse position
The absolute mouse position is used primarily in window applications, where the mouse position constraints are desirable. The mouse position (0,0) corresponds to the upper-left corner of your application window. The maximum mouse position depends always on the size of the window. Take special care when the mouse cursor is outside the application window. The behavior of LuaSDL in this situation is highly dependent on the currently used operating system! In most cases, you won't get any events related to the mouse cursor motion.
The main advantage of this is that you can use the mouse cursor position reported directly by LuaSDL to precisely manipulate GUI elements inside of the application window. This approach is used also with tablet touch input devices, where you always get absolute positions.
How to do it…
The following mouse movement handler function shows a simple way to get the absolute mouse cursor position:
[SDL.SDL_MOUSEMOTION] = function(raw_event) local event = raw_event.motion
The absolute mouse position is stored in x
and y
attributes:
mouseX = event.x mouseY = event.y end,
- Java Web開發學習手冊
- Jenkins Continuous Integration Cookbook(Second Edition)
- Statistical Application Development with R and Python(Second Edition)
- 大話Java:程序設計從入門到精通
- 細說Python編程:從入門到科學計算
- 從零開始學Python網絡爬蟲
- HTML5+CSS3+jQuery Mobile APP與移動網站設計從入門到精通
- Python計算機視覺和自然語言處理
- Scala Functional Programming Patterns
- Hacking Android
- Software-Defined Networking with OpenFlow(Second Edition)
- JavaScript語法簡明手冊
- Android熱門應用開發詳解
- Scala編程(第4版)
- Go語言編程之旅:一起用Go做項目