diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2010-04-17 10:52:14 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2010-04-17 10:52:14 +0400 |
commit | 795b438bf5565a87765edb880318b7e241714270 (patch) | |
tree | c76292cfa5e11b1eab41484342fb04b5e9fb2a06 /source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp | |
parent | 6562e6a4d1c12166b53322de131ed65867eb026d (diff) |
Patch #21789 - BGE Keyboard and Mouse Python types - by Mitchell Stokes(Moguri)
The patch exposes mouse and keyboard read-only properties in the GameLogic module
Also renames bge.keys to bge.events (* Note: name of bge submodules (logic, render, ...) may change before 2.5 final release [right Campbell?]).
"""
This patch adds two new types to the BGE:
SCA_PythonKeyboard
SCA_PythonMouse
These two types allow users to make use of the keyboard and mouse without the need for a keyboard or mouse sensor.
SCA_PythonKeyboard has an events property that acts just like SCA_KeyboardSensor.events.
SCA_PythonMouse also has an events property to check for mouse events. Further more it supports getting and setting normalized cursor position (from 0.0 to 1.0) with SCA_PythonMouse.position. The cursor can be shown/hidden using SCA_PythonMouse.visible.
"""
Its use is similar with current mouse and keyboard controllers. With the exception of mouse position being normalized and writable as well (replacing Rasterizer.setMousePosition).
Code Sample:
######
from bge import logic, events
mouse = logic.mouse
keyboard = logic.keyboard
for key,status in keyboard.events:
if status == logic.KX_INPUT_JUST_ACTIVATED:
if key == events.WKEY:
print(mouse.position)
# move_forward()
mouse.visible = True # turn cursor visible
mouse.position = 0.5,0.5 # centralize mouse - use tuple
######
* Important Note: mouse.position still will not work properly for Letterbox mode.
In order to fix letterboxing I may need to move the set x,y mouse function to inside the canvas code (to avoid duplicated code between mouse sensor and bge.logic.mouse). I'll leave this for another commit though.
Thanks Mitchell for the work on that.
Diffstat (limited to 'source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp')
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp index 0a96fbbe503..4eb9a4cfcd7 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp @@ -79,6 +79,8 @@ void GPG_Canvas::SetMousePosition(int x, int y) void GPG_Canvas::SetMouseState(RAS_MouseState mousestate) { + m_mousestate = mousestate; + if (m_window) { switch (mousestate) |