Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard support #14

Merged
merged 2 commits into from May 17, 2013
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Add keyboard support

  • Loading branch information
pcwalton committed May 17, 2013
commit 32525c17d6116837edd4d636c1b739993428d197
32 glut.rs
@@ -9,7 +9,9 @@

/* automatically generated by rust-bindgen */

use glut::bindgen::{glutCreateWindow, glutDestroyWindow, glutDisplayFunc, glutMouseFunc, glutMotionFunc, glutPassiveMotionFunc, glutGet, glutGetWindow};
use glut::bindgen::{glutCreateWindow, glutDestroyWindow, glutDisplayFunc, glutMouseFunc};
use glut::bindgen::{glutKeyboardFunc, glutGetModifiers, glutMotionFunc, glutPassiveMotionFunc};
use glut::bindgen::{glutGet, glutGetWindow};
use glut::bindgen::{glutInit, glutInitDisplayMode, glutPostRedisplay, glutReshapeFunc};
use glut::bindgen::{glutReshapeWindow, glutSetWindow, glutSwapBuffers, glutTimerFunc};
use core::libc::*;
@@ -46,6 +48,10 @@ pub struct Window(c_int);

pub static DOUBLE: c_uint = 2 as c_uint;

pub static ACTIVE_SHIFT: c_int = 1;
pub static ACTIVE_CTRL: c_int = 2;
pub static ACTIVE_ALT: c_int = 4;

static WINDOW_WIDTH: GLenum = 102;
static WINDOW_HEIGHT: GLenum = 103;

@@ -117,6 +123,24 @@ pub fn display_func(callback: @fn()) {
}
}

pub fn keyboard_callback_tls_key(_: @@fn(key: c_uchar, x: c_int, y: c_int)) {
// Empty.
}

pub extern fn keyboard_callback(key: c_uchar, x: c_int, y: c_int) {
unsafe {
let callback = local_data_get(keyboard_callback_tls_key).get();
(*callback)(key, x, y)
}
}

pub fn keyboard_func(callback: @fn(key: c_uchar, x: c_int, y: c_int)) {
unsafe {
local_data_set(keyboard_callback_tls_key, @callback);
glutKeyboardFunc(keyboard_callback);
}
}

pub fn mouse_callback_tls_key(_callback: @@fn(button: c_int, state: c_int, x: c_int, y: c_int)) {
// Empty.
}
@@ -262,6 +286,12 @@ pub fn get(state: State) -> c_int {
}
}

pub fn get_modifiers() -> c_int {
unsafe {
glutGetModifiers()
}
}

#[cfg(target_os="macos")]
#[nolink]
#[link_args="-framework GLUT"]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.