This commit is contained in:
Kevin Hamacher 2019-11-08 11:56:02 +01:00
commit 5db0dd0a16
5 changed files with 145 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

82
Cargo.lock generated Normal file
View File

@ -0,0 +1,82 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "csfml-audio-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"csfml-system-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sfml-build 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "csfml-graphics-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"csfml-system-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"csfml-window-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sfml-build 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "csfml-system-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"sfml-build 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "csfml-window-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"csfml-system-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sfml-build 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "demo"
version = "0.1.0"
dependencies = [
"sfml 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sfml"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"csfml-audio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"csfml-graphics-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"csfml-system-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"csfml-window-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"widestring 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sfml-build"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "widestring"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum csfml-audio-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b928d3b663c6d4d45c330a254b432e3a228cba3851207bda5542fb9b978a8242"
"checksum csfml-graphics-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e4f0c658045598446f1968df8acf047787e70dc44962686f54ec0d9835aed3e"
"checksum csfml-system-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebeefc2da7f0568d54eb798706bbb1aa6fd589cda7a84c1188b860773ace35d"
"checksum csfml-window-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d8d000d0a6646167f7ccece9855718145c3e25ab738c9bc8ffeedfa17c41dd3"
"checksum sfml 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "513d5e9ff2e56ae75c7ab943fbd15880fd685230d9ddc0abb853c1374ee66129"
"checksum sfml-build 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f83a1ad7f7c79c9273019b2abfacbd4fa7150d23caca8cae586f0f1ea43b151"
"checksum widestring 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "effc0e4ff8085673ea7b9b2e3c73f6bd4d118810c9009ed8f1e16bd96c331db6"

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "demo"
version = "0.1.0"
authors = ["Kevin Hamacher <kevin.hamacher@ruhr-uni-bochum.de>"]
edition = "2018"
[dependencies]
sfml = "*"

Binary file not shown.

53
src/main.rs Normal file
View File

@ -0,0 +1,53 @@
#![allow(dead_code)]
extern crate sfml;
use sfml::graphics::*;
use sfml::system::*;
use sfml::window::*;
fn main() {
let mut window = RenderWindow::new((800, 600), "Window", Style::CLOSE, &Default::default());
window.set_mouse_cursor_visible(false);
window.set_framerate_limit(60);
let font = Font::from_file("resources/OpenSans-Regular.ttf").unwrap();
let mut circle = CircleShape::new(4., 30);
let mp_text = Text::new("FooBar", &font, 14);
let mut grabbed = false;
let mut cursor_visible = true;
loop {
while let Some(ev) = window.poll_event() {
match ev {
Event::Closed => return,
Event::KeyPressed { code, .. } => match code {
Key::W => window.set_mouse_position(Vector2i::new(400, 300)),
Key::D => {
let dm = VideoMode::desktop_mode();
let center = Vector2i::new(dm.width as i32 / 2, dm.height as i32 / 2);
mouse::set_desktop_position(center);
}
Key::V => {
cursor_visible = !cursor_visible;
window.set_mouse_cursor_visible(cursor_visible);
}
Key::G => {
grabbed = !grabbed;
window.set_mouse_cursor_grabbed(grabbed);
}
_ => {}
},
_ => {}
}
}
let mp = window.mouse_position();
circle.set_position((mp.x as f32, mp.y as f32));
window.clear(Color::BLACK);
window.draw(&circle);
window.draw(&mp_text);
window.display();
}
}