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

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,
主站蜘蛛池模板: 三明市| 河北省| 中江县| 娄烦县| 义马市| 睢宁县| 靖西县| 莲花县| 湘潭市| 东台市| 利川市| 遵化市| 郸城县| 云阳县| 峡江县| 万荣县| 法库县| 北海市| 沭阳县| 兴海县| 定襄县| 和龙市| 黄平县| 德清县| 敖汉旗| 鄂托克前旗| 高阳县| 大竹县| 资溪县| 抚顺县| 淄博市| 萨嘎县| 西藏| 台山市| 宁波市| 满洲里市| 桃江县| 潜山县| 安陆市| 福泉市| 五家渠市|