Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Merge pull request #88 from tomassedovic/sys
Browse files Browse the repository at this point in the history
Add some missing TCOD_sys functions
  • Loading branch information
tomassedovic committed Jan 24, 2015
2 parents d75314c + 8127e3c commit 8caf08e
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tcod"
description = "The Rust bindings for the Doryen library (a.k.a. libtcod)."
version = "0.4.4"
version = "0.4.5"
homepage = "https://github.com/tomassedovic/tcod-rs"
repository = "https://github.com/tomassedovic/tcod-rs"
readme = "README.md"
Expand All @@ -25,7 +25,7 @@ bitflags = "0.1"

[dependencies.tcod-sys]
path = "tcod-sys"
version = "2.0.1"
version = "2.0.2"

# TODO: temporarily disabling debuginfo until this is fixed:
# https://github.com/rust-lang/rust/issues/17257
Expand Down
78 changes: 78 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,8 @@ pub enum BackgroundFlag {
pub mod system {
use std;
use std::num::FromPrimitive;
use std::io::fs::PathExtensions;
use std::time::Duration;
use ffi;
use libc::c_char;
use ::{c_bool,
Expand Down Expand Up @@ -1075,6 +1077,82 @@ pub mod system {
}
}

pub fn sleep(time: Duration) {
unsafe {
ffi::TCOD_sys_sleep_milli(time.num_milliseconds() as u32);
}
}

pub fn get_elapsed_time() -> Duration {
let ms: u32 = unsafe {
ffi::TCOD_sys_elapsed_milli()
};
return Duration::milliseconds(ms as i64)
}

pub fn save_screenshot(path: &std::path::Path) {
assert!(path.exists());
let c_path = std::ffi::CString::from_slice(path.as_vec());
unsafe {
ffi::TCOD_sys_save_screenshot(c_path.as_ptr());
}
}

pub fn save_screenshot_auto() {
unsafe {
ffi::TCOD_sys_save_screenshot(std::ptr::null());
}
}

pub fn force_fullscreen_resolution(width: i32, height: i32) {
assert!(width > 0 && height > 0);
unsafe {
ffi::TCOD_sys_force_fullscreen_resolution(width, height);
}
}

pub fn get_current_resolution() -> (i32, i32) {
let mut width: i32 = 0;
let mut height: i32 = 0;
unsafe {
ffi::TCOD_sys_get_current_resolution(&mut width, &mut height);
}
(width, height)
}

pub fn get_fullscreen_offset() -> (i32, i32) {
let mut x: i32 = 0;
let mut y: i32 = 0;
unsafe {
ffi::TCOD_sys_get_fullscreen_offsets(&mut x, &mut y);
}
(x, y)
}

pub fn get_char_size() -> (i32, i32) {
let mut width: i32 = 0;
let mut height: i32 = 0;
unsafe {
ffi::TCOD_sys_get_char_size(&mut width, &mut height);
}
(width, height)
}

pub fn set_clipboard(value: &str) {
let c_str = std::ffi::CString::from_slice(value.as_bytes());
unsafe {
ffi::TCOD_sys_clipboard_set(c_str.as_ptr());
}
}

pub fn get_clipboard() -> String {
unsafe {
let c_ptr = ffi::TCOD_sys_clipboard_get();
let c_str = std::ffi::c_str_to_bytes(&c_ptr);
std::str::from_utf8(c_str).unwrap().to_string()
}
}

pub fn check_for_event(event_mask: EventFlags) -> (EventFlags, Event) {
let mut c_key_state = ffi::TCOD_key_t {
vk: 0,
Expand Down
2 changes: 1 addition & 1 deletion tcod-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tcod-sys"
description = "Raw FFI bindings & build script to link against libtcod."
version = "2.0.1"
version = "2.0.2"
license = "WTFPL"
homepage = "https://github.com/tomassedovic/tcod-rs"
repository = "https://github.com/tomassedovic/tcod-rs/tree/master/tcod-sys"
Expand Down
2 changes: 1 addition & 1 deletion tcod-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ extern "C" {
buf: *mut ::libc::c_uchar, size: uint32)
-> _bool;
pub fn TCOD_sys_clipboard_set(value: *const ::libc::c_char);
pub fn TCOD_sys_clipboard_get() -> *mut ::libc::c_char;
pub fn TCOD_sys_clipboard_get() -> *const ::libc::c_char;
pub fn TCOD_thread_new(func:
::std::option::Option<extern "C" fn
(arg1:
Expand Down

0 comments on commit 8caf08e

Please sign in to comment.