Permalink
Browse files

Added support for CEGUI and an option to show or hide the mouse.

Added support for CEGUI and had to change a couple of callback and function
parameter lists for it, so code that uses the previous version of clois-lane
will have to be updated.
Also added the option to show or hide your mouse pointer.
  • Loading branch information...
1 parent 5fa1343 commit b1dc1f97cb34b33f05d7dd78aca98d5ef70c0cab @aerique committed Aug 7, 2009
Showing with 130 additions and 34 deletions.
  1. +22 −0 clois-lane-cegui.asd
  2. +1 −1 clois-lane.asd
  3. +18 −16 libclois-lane/src/libclois-lane.cpp
  4. +52 −0 src/actions-cegui.lisp
  5. +12 −8 src/actions.lisp
  6. +23 −8 src/cffi.lisp
  7. +2 −1 src/package.lisp
View
@@ -0,0 +1,22 @@
+;;;; -*- Mode: LISP; Syntax: COMMON-LISP -*-
+;;;;
+;;;; clois-lane-cegui.asd
+;;;;
+;;;; author: Erik Winkels (aerique@xs4all.nl)
+;;;;
+;;;; See the LICENSE file in the clois-lane root directory for more info.
+
+(in-package :cl-user)
+
+(defpackage :clois-lane-system
+ (:use :cl :asdf))
+
+(in-package :clois-lane-system)
+
+(asdf:defsystem :clois-lane-cegui
+ :version "1.2.0.2"
+ :components
+ ((:module src
+ :components
+ ((:file "actions-cegui"))))
+ :depends-on (:clois-lane))
View
@@ -14,7 +14,7 @@
(in-package :clois-lane-system)
(asdf:defsystem :clois-lane
- :version "1.2.0.1"
+ :version "1.2.0.2"
:components
((:module src
:components
@@ -14,9 +14,9 @@ using namespace std;
// Pointers to Common Lisp functions
-void (*clfun_key_pressed)(int);
-void (*clfun_key_released)(int);
-void (*clfun_mouse_moved)(int, int);
+void (*clfun_key_pressed)(int, unsigned int);
+void (*clfun_key_released)(int, unsigned int);
+void (*clfun_mouse_moved)(int, int, int, int, int, int);
void (*clfun_mouse_pressed)(int);
void (*clfun_mouse_released)(int);
@@ -36,7 +36,7 @@ class InputHandler : OIS::KeyListener, public OIS::MouseListener
OIS::Mouse* mouse;
public:
- InputHandler(std::string hWnd);
+ InputHandler(std::string hWnd, bool hide_mouse);
~InputHandler();
void capture();
@@ -55,7 +55,7 @@ class InputHandler : OIS::KeyListener, public OIS::MouseListener
// Constructors
-InputHandler::InputHandler(std::string hWnd)
+InputHandler::InputHandler(std::string hWnd, bool hide_mouse)
{
OIS::ParamList pl;
@@ -66,7 +66,11 @@ InputHandler::InputHandler(std::string hWnd)
pl.insert(make_pair("XAutoRepeatOn", "false"));
pl.insert(make_pair("x11_keyboard_grab", "false"));
pl.insert(make_pair("x11_mouse_grab", "false"));
- pl.insert(make_pair("x11_mouse_hide", "false"));
+ if (hide_mouse) {
+ pl.insert(make_pair("x11_mouse_hide", "true"));
+ } else {
+ pl.insert(make_pair("x11_mouse_hide", "false"));
+ }
#endif
// XXX: this should be settable from CL
@@ -111,7 +115,7 @@ void InputHandler::capture()
(ois->createInputObject(OIS::OISMouse, true));
mouse->setEventCallback(this);
- cout << "[liblois-lane] Keyboard and mouse acquired!" << endl;
+ cout << "[libclois-lane] Keyboard and mouse acquired!" << endl;
} catch (OIS::Exception &e) {
cout << "[libclois-lane] " << e.eText << endl;
}
@@ -144,24 +148,22 @@ void InputHandler::setWindowExtents(int width, int height)
bool InputHandler::keyPressed(const OIS::KeyEvent &evt)
{
- clfun_key_pressed(evt.key);
+ clfun_key_pressed(evt.key, evt.text);
return true;
}
bool InputHandler::keyReleased(const OIS::KeyEvent &evt)
{
- clfun_key_released(evt.key);
+ clfun_key_released(evt.key, evt.text);
return true;
}
bool InputHandler::mouseMoved(const OIS::MouseEvent &evt)
{
- // This is incomplete and only works for the x and y axes.
- // Note: the scrollwheel and buttons beyond the fifth also count
- // as additional axes.
- clfun_mouse_moved(evt.state.X.rel, evt.state.Y.rel);
+ clfun_mouse_moved(evt.state.X.rel, evt.state.Y.rel, evt.state.Z.rel,
+ evt.state.X.abs, evt.state.Y.abs, evt.state.Z.abs);
return true;
}
@@ -191,7 +193,7 @@ extern "C"
// Prototypes
void ois_capture();
- InputHandler* ois_create_input_system(const char*);
+ InputHandler* ois_create_input_system(const char*, bool);
void ois_set_window_extents(int, int);
@@ -203,14 +205,14 @@ extern "C"
}
- InputHandler* ois_create_input_system(const char* hWnd)
+ InputHandler* ois_create_input_system(const char* hWnd, bool hide_mouse)
{
//unsigned long hWnd;
//rw->getCustomAttribute("WINDOW", &hWnd);
if (ois_input_handler == 0)
{
- ois_input_handler = new InputHandler(hWnd);
+ ois_input_handler = new InputHandler(hWnd, hide_mouse);
}
return ois_input_handler;
View
@@ -0,0 +1,52 @@
+;;;; -*- Mode: LISP; Syntax: COMMON-LISP -*-
+;;;;
+;;;; actions.lisp
+;;;;
+;;;; author: Erik Winkels (aerique@xs4all.nl)
+;;;;
+;;;; See the LICENSE file in the clois-lane root directory for more info.
+
+(in-package :clois-lane)
+
+
+;;; Functions
+
+(defun handle-key-event (key text state)
+ (let* ((key-name (cdr (assoc key +scancodes+)))
+ (char (code-char text))
+ (action (cdr (assoc key-name *actions*)))
+ (default (cdr (assoc :key-default *actions*))))
+ (cond ((equal state :pressed)
+ (okra-cegui::inject-key-down key)
+ (okra-cegui::inject-char text))
+ ((equal state :released)
+ (okra-cegui::inject-key-up key)))
+ (cond (action (funcall action key char state))
+ (default (funcall default key char state)))))
+
+
+(defun handle-mouse-button-event (button state)
+ (let* ((mouse-button (intern (format nil "MOUSE-BUTTON-~A" button) :keyword))
+ (action (cdr (assoc mouse-button *actions*)))
+ (default (cdr (assoc :mouse-button-default *actions*))))
+ (cond ((equal state :pressed)
+ (okra-cegui::inject-mouse-button-down button))
+ ((equal state :released)
+ (okra-cegui::inject-mouse-button-up button)))
+ (cond (action (funcall action mouse-button state))
+ (default (funcall default mouse-button state)))))
+
+
+(defun handle-mouse-move-event (rel-x rel-y rel-z abs-x abs-y abs-z)
+ (let ((mouse-x (cdr (assoc :mouse-x *actions*)))
+ (mouse-y (cdr (assoc :mouse-y *actions*)))
+ (mouse-z (cdr (assoc :mouse-z *actions*)))
+ (mouse-default (cdr (assoc :mouse-move-default *actions*))))
+ (okra-cegui::inject-mouse-position (coerce abs-x 'float)
+ (coerce abs-y 'float))
+ (cond (mouse-x (funcall mouse-x :mouse-x rel-x abs-x))
+ (mouse-default (funcall mouse-default :mouse-x rel-x abs-x)))
+ (cond (mouse-y (funcall mouse-y :mouse-y rel-y abs-y))
+ (mouse-default (funcall mouse-default :mouse-y rel-y abs-y)))
+ (cond (mouse-z (funcall mouse-z :mouse-z rel-z abs-z))
+ (mouse-default (funcall mouse-default :mouse-z rel-z abs-z)))))
View
@@ -24,12 +24,13 @@
*actions*)
-(defun handle-key-event (key state)
+(defun handle-key-event (key text state)
(let* ((key-name (cdr (assoc key +scancodes+)))
+ (char (code-char text))
(action (cdr (assoc key-name *actions*)))
(default (cdr (assoc :key-default *actions*))))
- (cond (action (funcall action key state))
- (default (funcall default key state)))))
+ (cond (action (funcall action key char state))
+ (default (funcall default key char state)))))
(defun handle-mouse-button-event (button state)
@@ -40,14 +41,17 @@
(default (funcall default mouse-button state)))))
-(defun handle-mouse-move-event (x y)
+(defun handle-mouse-move-event (rel-x rel-y rel-z abs-x abs-y abs-z)
(let ((mouse-x (cdr (assoc :mouse-x *actions*)))
(mouse-y (cdr (assoc :mouse-y *actions*)))
+ (mouse-z (cdr (assoc :mouse-z *actions*)))
(mouse-default (cdr (assoc :mouse-move-default *actions*))))
- (cond (mouse-x (funcall mouse-x :mouse-x x))
- (mouse-default (funcall mouse-default :mouse-x x)))
- (cond (mouse-y (funcall mouse-y :mouse-y y))
- (mouse-default (funcall mouse-default :mouse-y y)))))
+ (cond (mouse-x (funcall mouse-x :mouse-x rel-x abs-x))
+ (mouse-default (funcall mouse-default :mouse-x rel-x abs-x)))
+ (cond (mouse-y (funcall mouse-y :mouse-y rel-y abs-y))
+ (mouse-default (funcall mouse-default :mouse-y rel-y abs-y)))
+ (cond (mouse-z (funcall mouse-z :mouse-z rel-z abs-z))
+ (mouse-default (funcall mouse-default :mouse-z rel-z abs-z)))))
(defun remove-action (key action)
View
@@ -14,9 +14,15 @@
(defcfun ("ois_capture" capture)
:void)
-(defcfun ("ois_create_input_system" create-input-system)
+
+(defcfun ("ois_create_input_system" ois-create-input-system)
:pointer
- (window :string))
+ (window :string)
+ (hide-mouse :boolean))
+
+(defun create-input-system (window &key (hide-mouse nil))
+ (ois-create-input-system window hide-mouse))
+
(defcfun ("ois_set_window_extents" set-window-extents)
:void
@@ -28,16 +34,22 @@
;;; Keyboard
-(defcallback key-pressed :void ((key :int))
- (handle-key-event key :pressed))
+(defcallback key-pressed
+ :void
+ ((key :int)
+ (text :unsigned-int))
+ (handle-key-event key text :pressed))
(defcvar "clfun_key_pressed" :pointer)
(setf *clfun-key-pressed* (get-callback 'key-pressed))
-(defcallback key-released :void ((key :int))
- (handle-key-event key :released))
+(defcallback key-released
+ :void
+ ((key :int)
+ (text :unsigned-int))
+ (handle-key-event key text :released))
(defcvar "clfun_key_released" :pointer)
@@ -46,8 +58,11 @@
;;; Mouse
-(defcallback mouse-moved :void ((mx :int) (my :int))
- (handle-mouse-move-event mx my))
+(defcallback mouse-moved
+ :void
+ ((rel-x :int) (rel-y :int) (rel-z :int)
+ (abs-x :int) (abs-y :int) (abs-z :int))
+ (handle-mouse-move-event rel-x rel-y rel-z abs-x abs-y abs-z))
(defcvar "clfun_mouse_moved" :pointer)
View
@@ -11,4 +11,5 @@
(defpackage :clois-lane
(:use :cl :cffi)
(:export :capture :create-input-system :set-window-extents
- :add-action :get-actions :remove-action :set-actions))
+ :add-action :enable-cegui-support :get-actions :remove-action
+ :set-actions))

0 comments on commit b1dc1f9

Please sign in to comment.