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

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,
主站蜘蛛池模板: 池州市| 石棉县| 昌宁县| 砚山县| 涟水县| 东平县| 南投县| 沾化县| 萨迦县| 建湖县| 鄂托克前旗| 遵化市| 嘉定区| 黎平县| 神木县| 靖江市| 永城市| 凤翔县| 西宁市| 天祝| 汝阳县| 西华县| 东至县| 阳泉市| 黔西| 泰来县| 平泉县| 张北县| 岳普湖县| 左贡县| 大新县| 临朐县| 宁晋县| 墨玉县| 沈丘县| 汉中市| 永德县| 静安区| 连平县| 抚顺市| 梁河县|