官术网_书友最值得收藏!

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,
主站蜘蛛池模板: 天峨县| 深圳市| 河间市| 会泽县| 迁西县| 三门峡市| 神木县| 金湖县| 漳平市| 敦煌市| 兴海县| 灯塔市| 临泽县| 东明县| 宝兴县| 长岛县| 罗田县| 龙山县| 永顺县| 广东省| 冷水江市| 汽车| 霍林郭勒市| 乌兰察布市| 岗巴县| 嘉峪关市| 秦皇岛市| 铜陵市| 临西县| 大洼县| 油尖旺区| 苍南县| 涿州市| 镇远县| 宿松县| 股票| 微山县| 临安市| 三穗县| 卢龙县| 宜宾市|