Skip to content
Browse files

Initial version.

  • Loading branch information...
0 parents commit f5126e4a52fc3405c5f1dc7cc54fe80b18cd5a96 @aerique committed Jun 17, 2009
31 CMakeLists.txt
@@ -0,0 +1,31 @@
+# CMakeLists.txt
+#
+# author: Erik Winkels (aerique@xs4all.nl)
+#
+# See the LICENSE file in the clois-lane root directory for more info.
+
+cmake_minimum_required(VERSION 2.6)
+
+project(libclois-lane)
+
+option(BUILD_SHARED_LIBS "build libclois-lane shared" ON)
+
+add_definitions(-g -O0 -Wall)
+
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules")
+
+# Find the OIS library and add its include files.
+# (find-package doesn't work on MinGW/MSYS yet)
+if (MINGW)
+ include_directories("C:/Software/OgreSDK/include/OIS")
+ set(OIS_LIBRARY_REL "C:/Software/OgreSDK/bin/release/OIS.dll")
+else (MINGW)
+ find_package(OIS REQUIRED)
+ include_directories(${OIS_INCLUDE_DIR})
+endif (MINGW)
+
+# Set some directories / variables.
+set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})
+set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib)
+
+add_subdirectory(${CMAKE_SOURCE_DIR}/libclois-lane/build)
32 LICENSE
@@ -0,0 +1,32 @@
+The BSD License
+
+Copyright (c) 2009, Erik Winkels
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * The name of its contributor may not be used to endorse or
+ promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 README.1st
@@ -0,0 +1,66 @@
+
+ What you need and should know to get the example running
+ ========================================================
+
+ General
+ -------
+ The startup scripts (the *.sh and *.bat files) expect to be
+ run from the examples directory.
+
+ Before you try to compile libclois-lane yourself try running
+ the example with the libraries that are in the clois-lane lib
+ directory.
+
+ Linux
+ -----
+ The Linux startup is written and tested using SBCL
+ (1.0.25.debian at the time of writing) and expects to find
+ 'sbcl' in the path.
+
+ It also expects to find necessary OIS libraries in either
+ /usr/local/lib or the clois-lane lib directory.
+
+ All these options are set in the *.sh file and can be changed
+ there.
+
+ If the libraries that come with the clois-lane distribution
+ don't work for you, you'll need to compile OIS (and
+ libclois-lane) yourself . Download the source from:
+ http://sourceforge.net/project/showfiles.php?group_id=149835&package_id=166954&release_id=583859
+ (you'll need "ois_1.2.0.tar.gz")
+
+ For libcloise-lane you'll need CMake as well (www.cmake.org).
+ Once that is installed issue:
+
+ > cmake -G "Unix Makefiles"
+
+ and then
+
+ > make
+
+ and the library should end up in the lib directory if all goes
+ well.
+
+ Windows
+ -------
+ The Windows startup script is written and tested using Clozure
+ CL and expects to find 'wx86cl' in the path.
+
+ All libraries are expected to be found in the lib directory of
+ the Buclet distribution.
+
+ All these settings are in the *.bat file and can be changed
+ there.
+
+ If libclois-lane.dll that comes with the clois-lane
+ distribution don't work for you, you'll need to compile it
+ yourself using MinGW. Check the README.MinGW file for more
+ information.
+
+ Note: you do not need to compile OIS.dll yourself! Get that
+ from the Ogre SDK (since that's the only one it has been
+ tested with): http://www.ogre3d.org/download/sdk (you'll need
+ "OGRE 1.6.x SDK for Code::Blocks + MinGW C++ Toolbox").
+
+
+ Erik Winkels, 2009-06-02
35 README.MinGW
@@ -0,0 +1,35 @@
+
+ This README is aimed at Windows users. If you're on a Unix
+ system I'm expecting you to be able to take care of yourself
+ and also expect you're using a distribution with a fairly
+ complete and non-retarded packaging system.
+
+ If your libs directory is empty you'll either to download them
+ from the homepage or you can try to compile them yourself in
+ which case you'll need to download and install MinGW, MSYS and
+ CMake:
+
+ o CMake: http://www.cmake.org/cmake/resources/software.html#latest
+ o MinGW: http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=240780
+ o MSYS: http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=24963
+ http://sourceforge.net/project/downloading.php?group_id=2435&filename=MSYS-1.0.10.exe&a=14697658
+
+ Install MinGW first and then MSYS. Use MSYS version 1.0.10.
+ There's guides and information on www.mingw.org if needed.
+ (http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite)
+
+ If all of this is done you can issue:
+
+ > cmake -G "MSYS Makefiles"
+
+ (not "MinGW Makefiles"!)
+
+ and then:
+
+ > make
+
+ and if everything goes right (probably not) it should end up
+ in the lib directory.
+
+
+ Erik Winkels, 2009-06-02
26 clois-lane.asd
@@ -0,0 +1,26 @@
+;;;; -*- Mode: LISP; Syntax: COMMON-LISP -*-
+;;;;
+;;;; clois-lane.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
+ :version "1.2.0.1"
+ :components
+ ((:module src
+ :components
+ ((:file "package")
+ (:file "actions" :depends-on ("package" "keyboard-scancodes"))
+ (:file "cffi" :depends-on ("package" "actions" "ois-lib"))
+ (:file "keyboard-scancodes" :depends-on ("package"))
+ (:file "ois-lib" :depends-on ("package")))))
+ :depends-on (:cffi))
43 cmake-modules/FindOIS.cmake
@@ -0,0 +1,43 @@
+# - Try to find OIS
+# Once done, this will define
+#
+# OIS_FOUND - system has OIS
+# OIS_INCLUDE_DIRS - the OIS include directories
+# OIS_LIBRARIES - link these to use OIS
+
+include(FindPkgMacros)
+findpkg_begin(OIS)
+
+# Get path, convert backslashes as ${ENV_${var}}
+getenv_path(OIS_HOME)
+getenv_path(OGRE_HOME)
+getenv_path(OGRE_SOURCE)
+
+# construct search paths
+set(OIS_PREFIX_PATH ${OIS_HOME} ${ENV_OIS_HOME}
+ ${OGRE_SOURCE}/Dependencies ${ENV_OGRE_SOURCE}/Dependencies
+ ${OGRE_HOME} ${ENV_OGRE_HOME})
+create_search_paths(OIS)
+# redo search if prefix path changed
+clear_if_changed(OIS_PREFIX_PATH
+ OIS_LIBRARY_FWK
+ OIS_LIBRARY_REL
+ OIS_LIBRARY_DBG
+ OIS_INCLUDE_DIR
+)
+
+set(OIS_LIBRARY_NAMES OIS)
+get_debug_names(OIS_LIBRARY_NAMES)
+
+use_pkgconfig(OIS_PKGC OIS)
+
+findpkg_framework(OIS)
+
+find_path(OIS_INCLUDE_DIR NAMES OIS.h HINTS ${OIS_INC_SEARCH_PATH} ${OIS_PKGC_INCLUDE_DIRS} PATH_SUFFIXES OIS)
+find_library(OIS_LIBRARY_REL NAMES ${OIS_LIBRARY_NAMES} HINTS ${OIS_LIB_SEARCH_PATH} ${OIS_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" release relwithdebinfo minsizerel)
+find_library(OIS_LIBRARY_DBG NAMES ${OIS_LIBRARY_NAMES_DBG} HINTS ${OIS_LIB_SEARCH_PATH} ${OIS_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" debug)
+make_library_set(OIS_LIBRARY)
+
+findpkg_finish(OIS)
+add_parent_dir(OIS_INCLUDE_DIRS OIS_INCLUDE_DIR)
+
132 cmake-modules/FindPkgMacros.cmake
@@ -0,0 +1,132 @@
+##################################################################
+# Provides some common functionality for the FindPackage modules
+##################################################################
+
+# Begin processing of package
+macro(findpkg_begin PREFIX)
+ if (NOT ${PREFIX}_FIND_QUIETLY)
+ message(STATUS "Looking for ${PREFIX}...")
+ endif ()
+endmacro(findpkg_begin)
+
+# Display a status message unless FIND_QUIETLY is set
+macro(pkg_message PREFIX)
+ if (NOT ${PREFIX}_FIND_QUIETLY)
+ message(STATUS ${ARGN})
+ endif ()
+endmacro(pkg_message)
+
+# Get environment variable, define it as ENV_$var and make sure backslashes are converted to forward slashes
+macro(getenv_path VAR)
+ set(ENV_${VAR} $ENV{${VAR}})
+ # replace won't work if var is blank
+ if (ENV_${VAR})
+ string( REGEX REPLACE "\\\\" "/" ENV_${VAR} ${ENV_${VAR}} )
+ endif ()
+endmacro(getenv_path)
+
+# Construct search paths for includes and libraries from a PREFIX_PATH
+macro(create_search_paths PREFIX)
+ foreach(dir ${${PREFIX}_PREFIX_PATH})
+ set(${PREFIX}_INC_SEARCH_PATH ${${PREFIX}_INC_SEARCH_PATH}
+ ${dir}/include ${dir}/include/${PREFIX} ${dir}/Headers)
+ set(${PREFIX}_LIB_SEARCH_PATH ${${PREFIX}_LIB_SEARCH_PATH}
+ ${dir}/lib ${dir}/lib/${PREFIX} ${dir}/Libs)
+ endforeach(dir)
+ set(${PREFIX}_FRAMEWORK_SEARCH_PATH ${${PREFIX}_PREFIX_PATH})
+endmacro(create_search_paths)
+
+# clear cache variables if a certain variable changed
+macro(clear_if_changed TESTVAR)
+ # test against internal check variable
+ if (NOT "${${TESTVAR}}" STREQUAL "${${TESTVAR}_INT_CHECK}")
+ message(STATUS "${TESTVAR} changed.")
+ foreach(var ${ARGN})
+ set(${var} "NOTFOUND" CACHE STRING "x" FORCE)
+ endforeach(var)
+ endif ()
+ set(${TESTVAR}_INT_CHECK ${${TESTVAR}} CACHE INTERNAL "x" FORCE)
+endmacro(clear_if_changed)
+
+# Try to get some hints from pkg-config, if available
+macro(use_pkgconfig PREFIX PKGNAME)
+ find_package(PkgConfig)
+ if (PKG_CONFIG_FOUND)
+ pkg_check_modules(${PREFIX} ${PKGNAME})
+ endif ()
+endmacro (use_pkgconfig)
+
+# Couple a set of release AND debug libraries (or frameworks)
+macro(make_library_set PREFIX)
+ if (${PREFIX}_FWK)
+ set(${PREFIX} ${${PREFIX}_FWK})
+ elseif (${PREFIX}_REL AND ${PREFIX}_DBG)
+ set(${PREFIX} optimized ${${PREFIX}_REL} debug ${${PREFIX}_DBG})
+ elseif (${PREFIX}_REL)
+ set(${PREFIX} ${${PREFIX}_REL})
+ elseif (${PREFIX}_DBG)
+ set(${PREFIX} ${${PREFIX}_DBG})
+ endif ()
+endmacro(make_library_set)
+
+# Generate debug names from given release names
+macro(get_debug_names PREFIX)
+ foreach(i ${${PREFIX}})
+ set(${PREFIX}_DBG ${${PREFIX}_DBG} ${i}d ${i}D ${i}_d ${i}_D)
+ endforeach(i)
+endmacro(get_debug_names)
+
+# Add the parent dir from DIR to VAR
+macro(add_parent_dir VAR DIR)
+ get_filename_component(${DIR}_TEMP "${${DIR}}/.." ABSOLUTE)
+ set(${VAR} ${${VAR}} ${${DIR}_TEMP})
+endmacro(add_parent_dir)
+
+# Do the final processing for the package find.
+macro(findpkg_finish PREFIX)
+ # skip if already processed during this run
+ if (NOT ${PREFIX}_FOUND)
+ if (${PREFIX}_INCLUDE_DIR AND ${PREFIX}_LIBRARY)
+ set(${PREFIX}_FOUND TRUE)
+ set(${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIR})
+ set(${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARY})
+ if (NOT ${PREFIX}_FIND_QUIETLY)
+ message(STATUS "Found ${PREFIX}: ${${PREFIX}_LIBRARIES}")
+ endif ()
+ else ()
+ if (NOT ${PREFIX}_FIND_QUIETLY)
+ message(STATUS "Could not locate ${PREFIX}")
+ endif ()
+ if (${PREFIX}_FIND_REQUIRED)
+ message(FATAL_ERROR "Required library ${PREFIX} not found! Install the library (including dev packages) and try again. If the library is already installed, set the missing variables manually in cmake.")
+ endif ()
+ endif ()
+
+ mark_as_advanced(${PREFIX}_INCLUDE_DIR ${PREFIX}_LIBRARY ${PREFIX}_LIBRARY_REL ${PREFIX}_LIBRARY_DBG ${PREFIX}_LIBRARY_FWK)
+ endif ()
+endmacro(findpkg_finish)
+
+
+# Slightly customised framework finder
+MACRO(findpkg_framework fwk)
+ IF(APPLE)
+ SET(${fwk}_FRAMEWORK_PATH
+ ${${fwk}_FRAMEWORK_SEARCH_PATH}
+ ${CMAKE_FRAMEWORK_PATH}
+ ~/Library/Frameworks
+ /Library/Frameworks
+ /System/Library/Frameworks
+ /Network/Library/Frameworks
+ )
+ FOREACH(dir ${${fwk}_FRAMEWORK_PATH})
+ SET(fwkpath ${dir}/${fwk}.framework)
+ IF(EXISTS ${fwkpath})
+ SET(${fwk}_FRAMEWORK_INCLUDES ${${fwk}_FRAMEWORK_INCLUDES}
+ ${fwkpath}/Headers ${fwkpath}/PrivateHeaders)
+ if (NOT ${fwk}_LIBRARY_FWK)
+ SET(${fwk}_LIBRARY_FWK "-framework ${fwk}" CACHE STRING "${fwk} library")
+ endif ()
+ ENDIF(EXISTS ${fwkpath})
+ ENDFOREACH(dir)
+ ENDIF(APPLE)
+ENDMACRO(findpkg_framework)
57 examples/example.lisp
@@ -0,0 +1,57 @@
+;;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-USER; Base: 10 -*-
+;;;;
+;;;; example.lisp
+
+(asdf:oos 'asdf:load-op :clois-lane)
+
+(use-package :clois-lane)
+
+
+;;; Variables
+
+(defvar *actions* '((:kc-escape . stop-running)
+ (:key-default . echo-self)
+ (:mouse-move-default . echo-self)))
+
+(defparameter *running* nil)
+
+
+;;; Functions
+
+(defun echo-self (key state)
+ (format t "~&key: ~S (~S); state: ~S~%"
+ key (cdr (assoc key clois-lane::+scancodes+)) state))
+
+
+(defun run-example ()
+ (set-actions *actions*)
+ (setf *running* t)
+ (format t "~&Press ESC to stop the loop...~%")
+ (loop while *running*
+ do (capture)
+ (sleep .1)))
+
+
+(defun stop-running (key state)
+ (declare (ignore key))
+ (when (equal state :released)
+ (setf *running* nil)))
+
+
+;;; Main Program
+
+(format t (concatenate 'string "~&~%===~%"
+ "Do a \"xwininfo -int | grep Window\\ id:\" in another xterm and click on~%"
+ "the window you're reading this message is in. Then do a:~%~%"
+ " (create-input-system \"window-id\")~%~%"
+ "and finally:~%~%"
+ " (run-example)~%"
+ "~%"
+ "If you're running on Windows, you'll need a program that will tell you a~%"
+ "window id f.e.: http://www.dennisbabkin.com/php/download.php?what=WinID~%"
+ "Also, the window id passed to create-input-system needs to be a string~%"
+ "and in base 10, not a hexadecimal value! So if WinID shows 0x123abc as~%"
+ "a window id, you'll need to type \"#x123abc\" on the repl and call:~%"
+ "~%"
+ " (create-input-system \"1194684\")~%"
+ "===~%"))
11 libclois-lane/build/CMakeLists.txt
@@ -0,0 +1,11 @@
+# CMakeLists.txt
+#
+# author: Erik Winkels (aerique@xs4all.nl)
+#
+# See the LICENSE file in the Okra root directory for more info.
+
+set(LIBCLOIS-LANE_SOURCE_FILES ../src/libclois-lane.cpp)
+
+add_library(clois-lane ${LIBCLOIS-LANE_SOURCE_FILES})
+
+target_link_libraries(clois-lane ${OIS_LIBRARY_REL})
224 libclois-lane/src/libclois-lane.cpp
@@ -0,0 +1,224 @@
+// libclois-lane.cpp
+//
+// author: Erik Winkels (aerique@xs4all.nl)
+//
+// See the LICENSE file in the clois-lane root directory for more info.
+
+#include <iostream>
+#include <string>
+
+#include "OIS.h"
+
+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_mouse_pressed)(int);
+void (*clfun_mouse_released)(int);
+
+
+// Variables
+
+//InputHandler* ois_input_handler;
+
+
+// Classes
+
+class InputHandler : OIS::KeyListener, public OIS::MouseListener
+{
+ private:
+ OIS::InputManager* ois;
+ OIS::Keyboard* keyboard;
+ OIS::Mouse* mouse;
+
+ public:
+ InputHandler(std::string hWnd);
+ ~InputHandler();
+
+ void capture();
+ void setWindowExtents(int width, int height);
+
+ // KeyListener
+ bool keyPressed(const OIS::KeyEvent &evt);
+ bool keyReleased(const OIS::KeyEvent &evt);
+
+ // MouseListener
+ bool mouseMoved(const OIS::MouseEvent &evt);
+ bool mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID);
+ bool mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID);
+};
+
+
+// Constructors
+
+InputHandler::InputHandler(std::string hWnd)
+{
+ OIS::ParamList pl;
+
+ pl.insert(make_pair("WINDOW", hWnd));
+
+ // XXX: this should be settable from CL
+#if defined(__linux) || defined(__unix)
+ 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"));
+#endif
+
+ // XXX: this should be settable from CL
+#if defined(_WIN32)
+ pl.insert(make_pair("w32_mouse", "DISCL_FOREGROUND" ));
+ //pl.insert(make_pair("w32_mouse", "DISCL_BACKGROUND" ));
+ pl.insert(make_pair("w32_mouse", "DISCL_NONEXCLUSIVE"));
+ pl.insert(make_pair("w32_keyboard", "DISCL_FOREGROUND"));
+ //pl.insert(make_pair("w32_keyboard", "DISCL_BACKGROUND"));
+ pl.insert(make_pair("w32_keyboard", "DISCL_NONEXCLUSIVE"));
+#endif
+
+ ois = OIS::InputManager::createInputSystem(pl);
+
+ keyboard = 0;
+ mouse = 0;
+}
+
+
+// Destructors
+
+InputHandler::~InputHandler()
+{
+ if (keyboard) { delete keyboard; }
+ if (mouse) { delete mouse; }
+ OIS::InputManager::destroyInputSystem(ois);
+}
+
+
+// Methods
+
+void InputHandler::capture()
+{
+ if (keyboard == 0 && mouse == 0)
+ {
+ try {
+ keyboard = static_cast<OIS::Keyboard*>
+ (ois->createInputObject(OIS::OISKeyboard, true));
+ keyboard->setEventCallback(this);
+
+ mouse = static_cast<OIS::Mouse*>
+ (ois->createInputObject(OIS::OISMouse, true));
+ mouse->setEventCallback(this);
+
+ cout << "[liblois-lane] Keyboard and mouse acquired!" << endl;
+ } catch (OIS::Exception &e) {
+ cout << "[libclois-lane] " << e.eText << endl;
+ }
+ }
+ else
+ {
+ try {
+ keyboard->capture();
+ mouse->capture();
+ } catch (OIS::Exception &e) {
+ cout << "[libclois-lane] " << e.eText << endl;
+ keyboard = 0;
+ mouse = 0;
+ }
+ }
+}
+
+
+void InputHandler::setWindowExtents(int width, int height)
+{
+ if (mouse) // might not be initialised yet
+ {
+ // Set mouse region. If window resizes, we should alter this as well.
+ const OIS::MouseState &ms = mouse->getMouseState();
+ ms.height = height;
+ ms.width = width;
+ }
+}
+
+
+bool InputHandler::keyPressed(const OIS::KeyEvent &evt)
+{
+ clfun_key_pressed(evt.key);
+ return true;
+}
+
+
+bool InputHandler::keyReleased(const OIS::KeyEvent &evt)
+{
+ clfun_key_released(evt.key);
+ 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);
+ return true;
+}
+
+
+bool InputHandler::mousePressed(const OIS::MouseEvent &evt,
+ OIS::MouseButtonID btn)
+{
+ clfun_mouse_pressed(btn);
+ return true;
+}
+
+
+bool InputHandler::mouseReleased(const OIS::MouseEvent &evt,
+ OIS::MouseButtonID btn)
+{
+ clfun_mouse_released(btn);
+ return true;
+}
+
+
+// C Wrapper Functions & Variables
+
+InputHandler* ois_input_handler;
+
+extern "C"
+{
+ // Prototypes
+
+ void ois_capture();
+ InputHandler* ois_create_input_system(const char*);
+ void ois_set_window_extents(int, int);
+
+
+ // Functions
+
+ void ois_capture()
+ {
+ ois_input_handler->capture();
+ }
+
+
+ InputHandler* ois_create_input_system(const char* hWnd)
+ {
+ //unsigned long hWnd;
+ //rw->getCustomAttribute("WINDOW", &hWnd);
+
+ if (ois_input_handler == 0)
+ {
+ ois_input_handler = new InputHandler(hWnd);
+ }
+
+ return ois_input_handler;
+ }
+
+
+ void ois_set_window_extents(int width, int height)
+ {
+ ois_input_handler->setWindowExtents(width, height);
+ }
+}
58 src/actions.lisp
@@ -0,0 +1,58 @@
+;;;; -*- 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)
+
+
+;;; Variables
+
+(defvar *actions* nil)
+
+
+;;; Functions
+
+(defun add-action (key action)
+ (setf *actions* (append *actions* (list (cons key action)))))
+
+
+(defun get-actions ()
+ *actions*)
+
+
+(defun handle-key-event (key state)
+ (let* ((key-name (cdr (assoc key +scancodes+)))
+ (action (cdr (assoc key-name *actions*)))
+ (default (cdr (assoc :key-default *actions*))))
+ (cond (action (funcall action key state))
+ (default (funcall default key 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 (action (funcall action mouse-button state))
+ (default (funcall default mouse-button state)))))
+
+
+(defun handle-mouse-move-event (x y)
+ (let ((mouse-x (cdr (assoc :mouse-x *actions*)))
+ (mouse-y (cdr (assoc :mouse-y *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)))))
+
+
+(defun remove-action (key action)
+ (setf *actions* (remove (cons key action) *actions* :test 'equal)))
+
+
+(defun set-actions (actions)
+ (setf *actions* actions))
70 src/cffi.lisp
@@ -0,0 +1,70 @@
+;;;; -*- Mode: LISP; Syntax: COMMON-LISP -*-
+;;;;
+;;;; cffi.lisp
+;;;;
+;;;; author: Erik Winkels (aerique@xs4all.nl)
+;;;;
+;;;; See the LICENSE file in the clois-lane root directory for more info.
+
+(in-package :clois-lane)
+
+
+;;; Wrapper Functions
+
+(defcfun ("ois_capture" capture)
+ :void)
+
+(defcfun ("ois_create_input_system" create-input-system)
+ :pointer
+ (window :string))
+
+(defcfun ("ois_set_window_extents" set-window-extents)
+ :void
+ (width :int)
+ (height :int))
+
+
+;;; OIS Callbacks
+
+;;; Keyboard
+
+(defcallback key-pressed :void ((key :int))
+ (handle-key-event key :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))
+
+(defcvar "clfun_key_released" :pointer)
+
+(setf *clfun-key-released* (get-callback 'key-released))
+
+
+;;; Mouse
+
+(defcallback mouse-moved :void ((mx :int) (my :int))
+ (handle-mouse-move-event mx my))
+
+(defcvar "clfun_mouse_moved" :pointer)
+
+(setf *clfun-mouse-moved* (get-callback 'mouse-moved))
+
+
+(defcallback mouse-pressed :void ((mbtn :int))
+ (handle-mouse-button-event mbtn :pressed))
+
+(defcvar "clfun_mouse_pressed" :pointer)
+
+(setf *clfun-mouse-pressed* (get-callback 'mouse-pressed))
+
+
+(defcallback mouse-released :void ((mbtn :int))
+ (handle-mouse-button-event mbtn :released))
+
+(defcvar "clfun_mouse_released" :pointer)
+
+(setf *clfun-mouse-released* (get-callback 'mouse-released))
160 src/keyboard-scancodes.lisp
@@ -0,0 +1,160 @@
+;;;; -*- Mode: LISP; Syntax: COMMON-LISP -*-
+;;;;
+;;;; keyboard-scancodes.lisp
+;;;;
+;;;; author: Erik Winkels (aerique@xs4all.nl)
+;;;;
+;;;; See the LICENSE file in the clois-lane root directory for more info.
+;;;;
+;;;; Keyboard scancodes pulled from OISKeyboard.h
+
+(in-package :clois-lane)
+
+
+;; defparameter because ASDF spazzes out on a defconstant
+(defvar +scancodes+
+ '((#x00 . :kc-unassigned)
+ (#x01 . :kc-escape)
+ (#x02 . :kc-1)
+ (#x03 . :kc-2)
+ (#x04 . :kc-3)
+ (#x05 . :kc-4)
+ (#x06 . :kc-5)
+ (#x07 . :kc-6)
+ (#x08 . :kc-7)
+ (#x09 . :kc-8)
+ (#x0a . :kc-9)
+ (#x0b . :kc-0)
+ (#x0c . :kc-minus) ; - on main keyboard
+ (#x0d . :kc-equals)
+ (#x0e . :kc-back) ; Backspace
+ (#x0f . :kc-tab)
+ (#x10 . :kc-q)
+ (#x11 . :kc-w)
+ (#x12 . :kc-e)
+ (#x13 . :kc-r)
+ (#x14 . :kc-t)
+ (#x15 . :kc-y)
+ (#x16 . :kc-u)
+ (#x17 . :kc-i)
+ (#x18 . :kc-o)
+ (#x19 . :kc-p)
+ (#x1a . :kc-lbracket)
+ (#x1b . :kc-rbracket)
+ (#x1c . :kc-return) ; Enter on main keyboard
+ (#x1d . :kc-lcontrol)
+ (#x1e . :kc-a)
+ (#x1f . :kc-s)
+ (#x20 . :kc-d)
+ (#x21 . :kc-f)
+ (#x22 . :kc-g)
+ (#x23 . :kc-h)
+ (#x24 . :kc-j)
+ (#x25 . :kc-k)
+ (#x26 . :kc-l)
+ (#x27 . :kc-semicolon)
+ (#x28 . :kc-apostrophe)
+ (#x29 . :kc-grave) ; accent
+ (#x2a . :kc-lshift)
+ (#x2b . :kc-backslash)
+ (#x2c . :kc-z)
+ (#x2d . :kc-x)
+ (#x2e . :kc-c)
+ (#x2f . :kc-v)
+ (#x30 . :kc-b)
+ (#x31 . :kc-n)
+ (#x32 . :kc-m)
+ (#x33 . :kc-comma)
+ (#x34 . :kc-period) ; . on main keyboard
+ (#x35 . :kc-slash) ; / on main keyboard
+ (#x36 . :kc-rshift)
+ (#x37 . :kc-multiply) ; * on numeric keypad
+ (#x38 . :kc-lmenu) ; left Alt
+ (#x39 . :kc-space)
+ (#x3a . :kc-capital)
+ (#x3b . :kc-f1)
+ (#x3c . :kc-f2)
+ (#x3d . :kc-f3)
+ (#x3e . :kc-f4)
+ (#x3f . :kc-f5)
+ (#x40 . :kc-f6)
+ (#x41 . :kc-f7)
+ (#x42 . :kc-f8)
+ (#x43 . :kc-f9)
+ (#x44 . :kc-f10)
+ (#x45 . :kc-numlock)
+ (#x46 . :kc-scroll) ; Scroll Lock
+ (#x47 . :kc-numpad7)
+ (#x48 . :kc-numpad8)
+ (#x49 . :kc-numpad9)
+ (#x4a . :kc-subtract) ; - on numeric keypad
+ (#x4b . :kc-numpad4)
+ (#x4c . :kc-numpad5)
+ (#x4d . :kc-numpad6)
+ (#x4e . :kc-add) ; + on numeric keypad
+ (#x4f . :kc-numpad1)
+ (#x50 . :kc-numpad2)
+ (#x51 . :kc-numpad3)
+ (#x52 . :kc-numpad0)
+ (#x53 . :kc-decimal) ; . on numeric keypad
+ (#x56 . :kc-oem_102) ; < > | on UK/Germany keyboards
+ (#x57 . :kc-f11)
+ (#x58 . :kc-f12)
+ (#x64 . :kc-f13) ; (NEC PC98)
+ (#x65 . :kc-f14) ; (NEC PC98)
+ (#x66 . :kc-f15) ; (NEC PC98)
+ (#x70 . :kc-kana) ; (Japanese keyboard)
+ (#x73 . :kc-abnt_c1) ; / ? on Portugese / Brazilian keyboards
+ (#x79 . :kc-convert) ; (Japanese keyboard)
+ (#x7b . :kc-noconvert) ; (Japanese keyboard)
+ (#x7d . :kc-yen) ; (Japanese keyboard)
+ (#x7e . :kc-abnt_c2) ; Numpad . on Portugese / Brazilian kbd
+ (#x8d . :kc-numpadequals+) ; = on numeric keypad (NEC PC98)
+ (#x90 . :kc-prevtrack) ; (KC-CIRCUMFLEX on Japanese keyboard)
+ (#x91 . :kc-at) ; (NEC PC98)
+ (#x92 . :kc-colon) ; (NEC PC98)
+ (#x93 . :kc-underline) ; (NEC PC98)
+ (#x94 . :kc-kanji) ; (Japanese keyboard)
+ (#x95 . :kc-stop) ; (NEC PC98)
+ (#x96 . :kc-ax) ; (Japan AX)
+ (#x97 . :kc-unlabeled) ; (J3100)
+ (#x99 . :kc-nexttrack) ; Next Track
+ (#x9c . :kc-numpadenter) ; Enter on numeric keypad
+ (#x9d . :kc-rcontrol)
+ (#xa0 . :kc-mute) ; Mute
+ (#xa1 . :kc-calculator) ; Calculator
+ (#xa2 . :kc-playpause) ; Play / Pause
+ (#xa4 . :kc-mediastop) ; Media Stop
+ (#xae . :kc-volumedown) ; Volume -
+ (#xb0 . :kc-volumeup) ; Volume +
+ (#xb2 . :kc-webhome) ; Web home
+ (#xb3 . :kc-numpadcomma) ; , on numeric keypad (NEC PC98)
+ (#xb5 . :kc-divide) ; / on numeric keypad
+ (#xb7 . :kc-sysrq)
+ (#xb8 . :kc-rmenu) ; right Alt
+ (#xc5 . :kc-pause) ; Pause
+ (#xc7 . :kc-home) ; Home on arrow keypad
+ (#xc8 . :kc-up) ; UpArrow on arrow keypad
+ (#xc9 . :kc-pgup) ; PgUp on arrow keypad
+ (#xcb . :kc-left) ; LeftArrow on arrow keypad
+ (#xcd . :kc-right) ; RightArrow on arrow keypad
+ (#xcf . :kc-end) ; End on arrow keypad
+ (#xd0 . :kc-down) ; DownArrow on arrow keypad
+ (#xd1 . :kc-pgdown) ; PgDn on arrow keypad
+ (#xd2 . :kc-insert) ; Insert on arrow keypad
+ (#xd3 . :kc-delete) ; Delete on arrow keypad
+ (#xdb . :kc-lwin) ; Left Windows key
+ (#xdc . :kc-rwin) ; Right Windows key
+ (#xdd . :kc-apps) ; AppMenu key
+ (#xde . :kc-power) ; System Power
+ (#xdf . :kc-sleep) ; System Sleep
+ (#xe3 . :kc-wake) ; System Wake
+ (#xe5 . :kc-websearch) ; Web Search
+ (#xe6 . :kc-webfavorites+) ; Web Favorites
+ (#xe7 . :kc-webrefresh) ; Web Refresh
+ (#xe8 . :kc-webstop) ; Web Stop
+ (#xe9 . :kc-webforward) ; Web Forward
+ (#xea . :kc-webback) ; Web Back
+ (#xeb . :kc-mycomputer) ; My Computer
+ (#xec . :kc-mail) ; Mail
+ (#xed . :kc-mediaselect))) ; Media Select
20 src/ois-lib.lisp
@@ -0,0 +1,20 @@
+;;;; -*- Mode: LISP; Syntax: COMMON-LISP -*-
+;;;;
+;;;; ois-lib.lisp
+;;;;
+;;;; author: Erik Winkels (aerique@xs4all.nl)
+;;;;
+;;;; See the LICENSE file in the clois-lane root directory for more info.
+
+(in-package :clois-lane)
+
+
+;;; Define and load the C wrapper.
+
+(define-foreign-library libclois-lane
+ (:windows "libclois-lane.dll")
+ (:unix "libclois-lane.so")
+ (t "libclois-lane"))
+
+(use-foreign-library libclois-lane)
+(format t "~&[clois-lane] foreign library libclois-lane loaded~%")
14 src/package.lisp
@@ -0,0 +1,14 @@
+;;;; -*- Mode: LISP; Syntax: COMMON-LISP -*-
+;;;;
+;;;; package.lisp
+;;;;
+;;;; 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
+ (:use :cl :cffi)
+ (:export :capture :create-input-system :set-window-extents
+ :add-action :get-actions :remove-action :set-actions))

0 comments on commit f5126e4

Please sign in to comment.
Something went wrong with that request. Please try again.