aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/cursor.rs49
-rw-r--r--examples/fullscreen.rs12
-rw-r--r--examples/multiwindow.rs10
-rw-r--r--examples/support/mod.rs13
-rw-r--r--examples/window.rs10
5 files changed, 67 insertions, 27 deletions
diff --git a/examples/cursor.rs b/examples/cursor.rs
new file mode 100644
index 0000000..0dced66
--- /dev/null
+++ b/examples/cursor.rs
@@ -0,0 +1,49 @@
+#[cfg(target_os = "android")]
+#[macro_use]
+extern crate android_glue;
+
+extern crate glutin;
+
+use glutin::{Event, ElementState, MouseCursor};
+
+mod support;
+
+#[cfg(target_os = "android")]
+android_start!(main);
+
+#[cfg(not(feature = "window"))]
+fn main() { println!("This example requires glutin to be compiled with the `window` feature"); }
+
+#[cfg(feature = "window")]
+fn main() {
+
+ let mut window = glutin::Window::new().unwrap();
+ window.set_title("A fantastic window!");
+ unsafe { window.make_current() };
+
+ let context = support::load(&window);
+ let cursors = [MouseCursor::Default, MouseCursor::Crosshair, MouseCursor::Hand, MouseCursor::Arrow, MouseCursor::Move, MouseCursor::Text, MouseCursor::Wait, MouseCursor::Help, MouseCursor::Progress, MouseCursor::NotAllowed, MouseCursor::ContextMenu, MouseCursor::NoneCursor, MouseCursor::Cell, MouseCursor::VerticalText, MouseCursor::Alias, MouseCursor::Copy, MouseCursor::NoDrop, MouseCursor::Grab, MouseCursor::Grabbing, MouseCursor::AllScroll, MouseCursor::ZoomIn, MouseCursor::ZoomOut, MouseCursor::EResize, MouseCursor::NResize, MouseCursor::NeResize, MouseCursor::NwResize, MouseCursor::SResize, MouseCursor::SeResize, MouseCursor::SwResize, MouseCursor::WResize, MouseCursor::EwResize, MouseCursor::NsResize, MouseCursor::NeswResize, MouseCursor::NwseResize, MouseCursor::ColResize, MouseCursor::RowResize];
+ let mut cursor_idx = 0;
+
+ while !window.is_closed() {
+ context.draw_frame((0.0, 1.0, 0.0, 1.0));
+ window.swap_buffers();
+
+ for event in window.wait_events() {
+ match event {
+ Event::KeyboardInput(ElementState::Pressed, _, _) => {
+ println!("Setting cursor to \"{:?}\"", cursors[cursor_idx]);
+ window.set_cursor(cursors[cursor_idx]);
+ if cursor_idx < cursors.len() - 1 {
+ cursor_idx += 1;
+ } else {
+ cursor_idx = 0;
+ }
+ },
+ _ => (),
+ }
+
+ }
+
+ }
+}
diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs
index bc15379..7c2ece8 100644
--- a/examples/fullscreen.rs
+++ b/examples/fullscreen.rs
@@ -1,7 +1,5 @@
-#![feature(phase)]
-
#[cfg(target_os = "android")]
-#[phase(plugin, link)]
+#[macro_use]
extern crate android_glue;
extern crate glutin;
@@ -21,15 +19,15 @@ fn main() {
// enumerating monitors
let monitor = {
for (num, monitor) in glutin::get_available_monitors().enumerate() {
- println!("Monitor #{}: {}", num, monitor.get_name());
+ println!("Monitor #{}: {:?}", num, monitor.get_name());
}
print!("Please write the number of the monitor to use: ");
- let num = from_str(stdin().read_line().unwrap().as_slice().trim())
+ let num = stdin().read_line().unwrap().as_slice().trim().parse()
.expect("Plase enter a number");
let monitor = glutin::get_available_monitors().nth(num).expect("Please enter a valid ID");
- println!("Using {}", monitor.get_name());
+ println!("Using {:?}", monitor.get_name());
monitor
};
@@ -49,6 +47,6 @@ fn main() {
context.draw_frame((0.0, 1.0, 0.0, 1.0));
window.swap_buffers();
- println!("{}", window.wait_events().collect::<Vec<glutin::Event>>());
+ println!("{:?}", window.wait_events().collect::<Vec<glutin::Event>>());
}
}
diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs
index 1f390cd..96b5842 100644
--- a/examples/multiwindow.rs
+++ b/examples/multiwindow.rs
@@ -1,7 +1,5 @@
-#![feature(phase)]
-
#[cfg(target_os = "android")]
-#[phase(plugin, link)]
+#[macro_use]
extern crate android_glue;
extern crate glutin;
@@ -22,15 +20,15 @@ fn main() {
let window2 = glutin::Window::new().unwrap();
let window3 = glutin::Window::new().unwrap();
- let t1 = Thread::spawn(move || {
+ let t1 = Thread::scoped(move || {
run(window1, (0.0, 1.0, 0.0, 1.0));
});
- let t2 = Thread::spawn(move || {
+ let t2 = Thread::scoped(move || {
run(window2, (0.0, 0.0, 1.0, 1.0));
});
- let t3 = Thread::spawn(move || {
+ let t3 = Thread::scoped(move || {
run(window3, (1.0, 0.0, 0.0, 1.0));
});
diff --git a/examples/support/mod.rs b/examples/support/mod.rs
index 6904653..94ef1a7 100644
--- a/examples/support/mod.rs
+++ b/examples/support/mod.rs
@@ -1,8 +1,5 @@
#![cfg(feature = "window")]
-#[phase(plugin)]
-extern crate gl_generator;
-
use glutin;
#[cfg(not(target_os = "android"))]
@@ -23,12 +20,12 @@ pub struct Context {
pub fn load(window: &glutin::Window) -> Context {
let gl = gl::Gl::load(window);
- let version = {
- use std::c_str::CString;
- unsafe { CString::new(gl.GetString(gl::VERSION) as *const i8, false) }
+ let version = unsafe {
+ use std::ffi;
+ String::from_utf8(ffi::c_str_to_bytes(&(gl.GetString(gl::VERSION) as *const i8)).to_vec()).unwrap()
};
- println!("OpenGL version {}", version.as_str().unwrap());
+ println!("OpenGL version {}", version);
Context { gl: gl }
}
@@ -80,7 +77,7 @@ impl Context {
}
#[cfg(target_os = "android")]
-static VERTEX_DATA: [f32, ..15] = [
+static VERTEX_DATA: [f32; 15] = [
-0.5, -0.5, 1.0, 0.0, 0.0,
0.0, 0.5, 0.0, 1.0, 0.0,
0.5, -0.5, 0.0, 0.0, 1.0
diff --git a/examples/window.rs b/examples/window.rs
index 910d6e6..37966c4 100644
--- a/examples/window.rs
+++ b/examples/window.rs
@@ -1,7 +1,5 @@
-#![feature(phase)]
-
#[cfg(target_os = "android")]
-#[phase(plugin, link)]
+#[macro_use]
extern crate android_glue;
extern crate glutin;
@@ -15,7 +13,7 @@ android_start!(main);
fn main() { println!("This example requires glutin to be compiled with the `window` feature"); }
#[cfg(feature = "window")]
-fn resize_callback(width: uint, height: uint) {
+fn resize_callback(width: u32, height: u32) {
println!("Window resized to {}x{}", width, height);
}
@@ -23,7 +21,7 @@ fn resize_callback(width: uint, height: uint) {
fn main() {
let mut window = glutin::Window::new().unwrap();
window.set_title("A fantastic window!");
- window.set_window_resize_callback(Some(resize_callback as fn(uint, uint)));
+ window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
unsafe { window.make_current() };
let context = support::load(&window);
@@ -32,6 +30,6 @@ fn main() {
context.draw_frame((0.0, 1.0, 0.0, 1.0));
window.swap_buffers();
- println!("{}", window.wait_events().collect::<Vec<glutin::Event>>());
+ println!("{:?}", window.wait_events().collect::<Vec<glutin::Event>>());
}
}