From bd31690c8d3b03d0625a73285442745d291cf07d Mon Sep 17 00:00:00 2001 From: Tomas Sedovic Date: Tue, 5 May 2015 12:51:58 +0200 Subject: [PATCH 1/2] Remove trailing whitespace --- examples/print_macros.rs | 12 ++++++------ src/chars.rs | 1 - src/colors.rs | 2 -- src/console.rs | 38 +++++++++++++++++++------------------- src/console_macros.rs | 38 +++++++++++++++++++------------------- src/input.rs | 1 - src/lib.rs | 13 ++++++------- src/system.rs | 1 - 8 files changed, 50 insertions(+), 56 deletions(-) diff --git a/examples/print_macros.rs b/examples/print_macros.rs index 8abda60b7..08a6e0253 100644 --- a/examples/print_macros.rs +++ b/examples/print_macros.rs @@ -10,15 +10,15 @@ fn main() { tcod_print!(root, At(1, 1), "Any text params may be {}", "formatted with println! formatting"); // One optional parameter - tcod_print!(root, At(1, 3), Wrap(6, 2), "Simple wrap"); - tcod_print!(root, At(1, 6), Bg(BackgroundFlag::None), "No background flag"); - tcod_print!(root, At(75, 8), Align(TextAlignment::Right), "Right align"); + tcod_print!(root, At(1, 3), Wrap(6, 2), "Simple wrap"); + tcod_print!(root, At(1, 6), Bg(BackgroundFlag::None), "No background flag"); + tcod_print!(root, At(75, 8), Align(TextAlignment::Right), "Right align"); // Two optional parameters. The optional parameters may be given in any order - tcod_print!(root, At(1, 10), Wrap(6, 2), Bg(BackgroundFlag::None), "Bg and wrap"); - tcod_print!(root, At(70, 12), Align(TextAlignment::Right), Wrap(6, 3), "Align and wrap"); - + tcod_print!(root, At(1, 10), Wrap(6, 2), Bg(BackgroundFlag::None), "Bg and wrap"); + tcod_print!(root, At(70, 12), Align(TextAlignment::Right), Wrap(6, 3), "Align and wrap"); + // Three optional parameters tcod_print!(root, At(40, 25), Wrap(10, 10), Bg(BackgroundFlag::None), Align(TextAlignment::Center), "This text is printed with every optional parameter, format: {} {}", "string", 1); diff --git a/src/chars.rs b/src/chars.rs index 870c1b3b8..378faedff 100644 --- a/src/chars.rs +++ b/src/chars.rs @@ -78,4 +78,3 @@ pub const POW1: char = '\u{fb}'; pub const POW3: char = '\u{fc}'; pub const POW2: char = '\u{fd}'; pub const BULLET_SQUARE: char = '\u{fe}'; - diff --git a/src/colors.rs b/src/colors.rs index 61bd8cb30..8b42529cd 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -297,5 +297,3 @@ pub const GOLD: Color = Color{r: 229, g: 191, b: 0}; pub const SILVER: Color = Color{r: 203, g: 203, b: 203}; pub const CELADON: Color = Color{r: 172, g: 255, b: 175}; pub const PEACH: Color = Color{r: 255, g: 159, b: 127}; - - diff --git a/src/console.rs b/src/console.rs index f5a2851c4..46c0df9f0 100644 --- a/src/console.rs +++ b/src/console.rs @@ -1,6 +1,6 @@ //! The console emulator handles the rendering of the game screen and the keyboard input //! -//! It provides the necessary traits and types for working with the different console types, +//! It provides the necessary traits and types for working with the different console types, //! including the [Console](./trait.Console.html) trait and the //! [Root](./struct.Root.html) and [Offscreen](./struct.Offscreen.html) console types. //! It's worth mentioning that only one `Root` console may exist at any given time, and it has to @@ -223,7 +223,7 @@ impl Root { /// This function changes the keyboard repeat times. The initial delay determines the /// number of milliseconds between the keypress and the time the keyboard repeat begins. - /// The interval sets the time between the keyboard repeat events. + /// The interval sets the time between the keyboard repeat events. /// With an initial delay of 0, the keyboard repeat feature is completely disabled. pub fn set_keyboard_repeat(&mut self, initial_delay: i32, interval: i32) { unsafe { @@ -270,7 +270,7 @@ impl Root { } } - /// This function will wait for a keypress event from the user, returning the [KeyState](../input/struct.KeyState.html) + /// This function will wait for a keypress event from the user, returning the [KeyState](../input/struct.KeyState.html) /// that represents the event. If `flush` is true, all pending keypresses are flushed from the /// keyboard buffer. If false, it returns the first element from it. pub fn wait_for_keypress(&mut self, flush: bool) -> KeyState { @@ -295,7 +295,7 @@ impl Root { /// This function checks if the user pressed a key. It returns the /// [KeyState](../input/struct.KeyState.html) representing the - /// event if they have, or `None` if they have not. + /// event if they have, or `None` if they have not. pub fn check_for_keypress(&self, status: KeyPressFlags) -> Option { let tcod_key = unsafe { ffi::TCOD_console_check_for_keypress(status.bits() as i32) @@ -494,7 +494,7 @@ impl<'a> RootInitializer<'a> { /// use tcod::console::{Console, Root, BackgroundFlag, TextAlignment}; /// /// let mut root = Root::initializer().size(80, 50).init(); -/// +/// /// root.print_ex(1, 1, BackgroundFlag::None, TextAlignment::Left, /// "Text aligned to left."); /// @@ -511,7 +511,7 @@ pub trait Console { /// Returns the underlying native `libtcod` representation of the current console. unsafe fn con(&self) -> ffi::TCOD_console_t; - /// Returns the default text alignment for the `Console` instance. For all the possible + /// Returns the default text alignment for the `Console` instance. For all the possible /// text alignment options, see the documentation for /// [TextAlignment](./enum.TextAlignment.html). fn get_alignment(&self) -> TextAlignment { @@ -526,7 +526,7 @@ pub trait Console { } } - /// Sets the default text alignment for the console. For all the possible + /// Sets the default text alignment for the console. For all the possible /// text alignment options, see the documentation for /// [TextAlignment](./enum.TextAlignment.html). fn set_alignment(&mut self, alignment: TextAlignment) { @@ -565,7 +565,7 @@ pub trait Console { } } - /// Sets the console's default foreground color. This is used in several printing functions. + /// Sets the console's default foreground color. This is used in several printing functions. fn set_default_foreground(&mut self, color: Color) { unsafe { ffi::TCOD_console_set_default_foreground(self.con(), *color.as_native()); @@ -661,10 +661,10 @@ pub trait Console { *color.as_native()); } } - + /// This function modifies every property of the given cell: /// - /// 1. Updates its background color according to the console's default and `background_flag`, + /// 1. Updates its background color according to the console's default and `background_flag`, /// see [BackgroundFlag](./enum.BackgroundFlag.html). /// 2. Updates its foreground color based on the default color set in the console /// 3. Sets its ASCII value to `glyph` @@ -700,7 +700,7 @@ pub trait Console { } } - /// Prints the text at the specified location. The position of the `x` and `y` + /// Prints the text at the specified location. The position of the `x` and `y` /// coordinates depend on the [TextAlignment](./enum.TextAlignment.html) set in the console: /// /// * `TextAlignment::Left`: leftmost character of the string @@ -717,8 +717,8 @@ pub trait Console { /// Prints the text at the specified location in a rectangular area with /// the dimensions: (width; height). If the text is longer than the width the /// newlines will be inserted. - fn print_rect(&mut self, - x: i32, y: i32, + fn print_rect(&mut self, + x: i32, y: i32, width: i32, height: i32, text: &str) { assert!(x >= 0 && y >= 0); @@ -748,8 +748,8 @@ pub trait Console { } /// Combines the functions of `print_ex` and `print_rect` - fn print_rect_ex(&mut self, - x: i32, y: i32, + fn print_rect_ex(&mut self, + x: i32, y: i32, width: i32, height: i32, background_flag: BackgroundFlag, alignment: TextAlignment, @@ -758,7 +758,7 @@ pub trait Console { unsafe { let c_text = CString::new(text.as_bytes()).unwrap(); ffi::TCOD_console_print_rect_ex(self.con(), x, y, width, height, - background_flag as u32, alignment as u32, + background_flag as u32, alignment as u32, c_text.as_ptr()); } } @@ -766,8 +766,8 @@ pub trait Console { /// Blits the contents of one console onto an other /// -/// It takes a region from a given console (with an arbitrary location, width and height) and superimposes -/// it on the destination console (at the given location). +/// It takes a region from a given console (with an arbitrary location, width and height) and superimposes +/// it on the destination console (at the given location). /// Note that when blitting, the source console's key color (set by `set_key_color`) will /// be ignored, making it possible to blit non-rectangular regions. /// @@ -865,7 +865,7 @@ impl Console for Box { } } -/// Represents the text alignment in console instances. +/// Represents the text alignment in console instances. #[repr(C)] #[derive(Copy, Clone)] pub enum TextAlignment { diff --git a/src/console_macros.rs b/src/console_macros.rs index 3f60da937..05562d69b 100644 --- a/src/console_macros.rs +++ b/src/console_macros.rs @@ -1,7 +1,7 @@ #[macro_export] macro_rules! tcod_print { // ABW - ($con: expr, At($x: expr, $y: expr), Align($alignment: expr), + ($con: expr, At($x: expr, $y: expr), Align($alignment: expr), Bg($bg: expr), Wrap($width: expr, $height: expr), $($arg: tt)*) => ( $con.print_rect_ex($x, $y, $width, $height, $bg, $alignment, format!($($arg)*).as_ref()); ); @@ -11,36 +11,36 @@ macro_rules! tcod_print { Wrap($width: expr, $height: expr), Bg($bg: expr), $($arg: tt)*) => ( $con.print_rect_ex($x, $y, $width, $height, $bg, $alignment, format!($($arg)*).as_ref()); ); - + // BAW - ($con: expr, At($x: expr, $y: expr), Bg($bg: expr), + ($con: expr, At($x: expr, $y: expr), Bg($bg: expr), Align($alignment: expr), Wrap($width: expr, $height: expr), $($arg: tt)*) => ( $con.print_rect_ex($x, $y, $width, $height, $bg, $alignment, format!($($arg)*).as_ref()); ); - + // BWA - ($con: expr, At($x: expr, $y: expr), Bg($bg: expr), + ($con: expr, At($x: expr, $y: expr), Bg($bg: expr), Wrap($width: expr, $height: expr), Align($alignment: expr), $($arg: tt)*) => ( $con.print_rect_ex($x, $y, $width, $height, $bg, $alignment, format!($($arg)*).as_ref()); ); - + // WAB - ($con: expr, At($x: expr, $y: expr), Wrap($width: expr, $height: expr), + ($con: expr, At($x: expr, $y: expr), Wrap($width: expr, $height: expr), Align($alignment: expr), Bg($bg: expr), $($arg: tt)*) => ( $con.print_rect_ex($x, $y, $width, $height, $bg, $alignment, format!($($arg)*).as_ref()); ); - + // WBA - ($con: expr, At($x: expr, $y: expr), Wrap($width: expr, $height: expr), + ($con: expr, At($x: expr, $y: expr), Wrap($width: expr, $height: expr), Bg($bg: expr), Align($alignment: expr), $($arg: tt)*) => ( $con.print_rect_ex($x, $y, $width, $height, $bg, $alignment, format!($($arg)*).as_ref()); ); - + // AB ($con: expr, At($x: expr, $y: expr), Align($bg: expr), Bg($alignment: expr), $($arg: tt)*) => ( $con.print_ex($x, $y, $bg, $alignment, format!($($arg)*).as_ref()); - ); - + ); + // AW ($con: expr, At($x: expr, $y: expr), Align($alignment: expr), Wrap($width: expr, $height: expr), $($arg: tt)*) => ( { @@ -48,12 +48,12 @@ macro_rules! tcod_print { $con.print_rect_ex($x, $y, $width, $height, bg, $alignment, format!($($arg)*).as_ref()); } ); - + // BA ($con: expr, At($x: expr, $y: expr), Bg($bg: expr), Align($alignment: expr), $($arg: tt)*) => ( $con.print_ex($x, $y, $bg, $alignment, format!($($arg)*).as_ref()); ); - + // BW ($con: expr, At($x: expr, $y: expr), Bg($bg: expr), Wrap($width: expr, $height: expr), $($arg: tt)*) => ( { @@ -61,7 +61,7 @@ macro_rules! tcod_print { $con.print_rect_ex($x, $y, $width, $height, $bg, alignment, format!($($arg)*).as_ref()); } ); - + // WA ($con: expr, At($x: expr, $y: expr), Wrap($width: expr, $height: expr), Align($alignment: expr), $($arg: tt)*) => ( { @@ -69,7 +69,7 @@ macro_rules! tcod_print { $con.print_rect_ex($x, $y, $width, $height, bg, $alignment, format!($($arg)*).as_ref()); } ); - + // WB ($con: expr, At($x: expr, $y: expr), Wrap($width: expr, $height: expr), Bg($bg: expr), $($arg: tt)*) => ( { @@ -77,7 +77,7 @@ macro_rules! tcod_print { $con.print_rect_ex($x, $y, $width, $height, $bg, alignment, format!($($arg)*).as_ref()); } ); - + // A ($con: expr, At($x: expr, $y: expr), Align($alignment: expr), $($arg: tt)*) => ( { @@ -85,7 +85,7 @@ macro_rules! tcod_print { $con.print_ex($x, $y, bg, $alignment, format!($($arg)*).as_ref()); } ); - + // B ($con: expr, At($x: expr, $y: expr), Bg($bg: expr), $($arg: tt)*) => ( { @@ -98,7 +98,7 @@ macro_rules! tcod_print { ($con: expr, At($x: expr, $y: expr), Wrap($width: expr, $height: expr), $($arg: tt)*) => ( $con.print_rect($x, $y, $width, $height, format!($($arg)*).as_ref()); ); - + // None ($con: expr, At($x: expr, $y: expr), $($arg: tt)*) => ( $con.print($x, $y, format!($($arg)*).as_ref()); diff --git a/src/input.rs b/src/input.rs index 22ade79f1..1298e904d 100644 --- a/src/input.rs +++ b/src/input.rs @@ -285,4 +285,3 @@ impl Iterator for EventIterator { check_for_event(KEY | MOUSE) } } - diff --git a/src/lib.rs b/src/lib.rs index 7c1ab7271..667931a67 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! libtcod bindings for Rust -//! +//! //! ## Description -//! [libtcod a.k.a. "The Doryen Library"](http://roguecentral.org/doryen/libtcod/) is a +//! [libtcod a.k.a. "The Doryen Library"](http://roguecentral.org/doryen/libtcod/) is a //! free, fast, portable and uncomplicated API for roguelike developpers providing lots of //! useful functions, such as: //! @@ -12,8 +12,8 @@ //! * Field of View //! * Portability (works on Windows, Linux and OS X) //! -//! For the full set of features see the [libtcod features page](http://roguecentral.org/doryen/libtcod/features/). -//! +//! For the full set of features see the [libtcod features page](http://roguecentral.org/doryen/libtcod/features/). +//! //! All raw bindings are available via the `tcod-sys` crate, however the `tcod-rs` library aims to //! provide safe, Rust-style wrappers for most of `libtcod`. These wrappers are not yet complete, //! however. @@ -35,7 +35,7 @@ //! * Containers //! * Pseudorandom generators //! * Compression utilities -//! +//! #[macro_use] extern crate bitflags; @@ -55,6 +55,5 @@ pub mod system; mod bindings; mod console_macros; -pub type RootConsole = console::Root; +pub type RootConsole = console::Root; pub type OffscreenConsole = console::Offscreen; - diff --git a/src/system.rs b/src/system.rs index 24bdee997..9446bd8e1 100644 --- a/src/system.rs +++ b/src/system.rs @@ -102,4 +102,3 @@ pub fn get_clipboard() -> String { std::str::from_utf8(c_str).unwrap().to_string() } } - From 82535c1df8657be8bd7359391a41a29bc70f249d Mon Sep 17 00:00:00 2001 From: Tomas Sedovic Date: Tue, 5 May 2015 13:02:23 +0200 Subject: [PATCH 2/2] Use Path everywhere for setting custom font `set_custom_font` used to take `&::std::path::Path`, but `RootInitializer::font` was using a `&str`. This switches to `&Path` for both so we're consistent. --- src/console.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/console.rs b/src/console.rs index 46c0df9f0..f949dcbb8 100644 --- a/src/console.rs +++ b/src/console.rs @@ -57,6 +57,7 @@ extern crate std; use std::marker::PhantomData; +use std::path::Path; use bindings::ffi; use bindings::{AsNative, FromNative, c_bool, CString, keycode_from_u32}; @@ -341,7 +342,7 @@ impl Root { } } - fn set_custom_font(font_path: &std::path::Path, + fn set_custom_font(font_path: &Path, font_layout: FontLayout, font_type: FontType, nb_char_horizontal: i32, @@ -387,6 +388,7 @@ struct FontDimensions(i32, i32); /// `RootInitializer` instance: /// /// ```rust +/// use std::path::Path; /// use tcod::console::{Root, FontLayout, Renderer}; /// /// fn main() { @@ -394,7 +396,7 @@ struct FontDimensions(i32, i32); /// .size(80, 20) /// .title("Example") /// .fullscreen(true) -/// .font("terminal.png", FontLayout::AsciiInCol) +/// .font(&Path::new("terminal.png"), FontLayout::AsciiInCol) /// .renderer(Renderer::GLSL) /// .init(); /// } @@ -404,7 +406,7 @@ pub struct RootInitializer<'a> { height: i32, title: &'a str, is_fullscreen: bool, - font_path: &'a str, + font_path: &'a Path, font_layout: FontLayout, font_type: FontType, font_dimension: FontDimensions, @@ -418,7 +420,7 @@ impl<'a> RootInitializer<'a> { height: 25, title: "Main Window", is_fullscreen: false, - font_path: "terminal.png", + font_path: &Path::new("terminal.png"), font_layout: FontLayout::AsciiInCol, font_type: FontType::Default, font_dimension: FontDimensions(0, 0), @@ -442,7 +444,7 @@ impl<'a> RootInitializer<'a> { self } - pub fn font(&mut self, path: &'a str, font_layout: FontLayout) -> &mut RootInitializer<'a> { + pub fn font(&mut self, path: &'a Path, font_layout: FontLayout) -> &mut RootInitializer<'a> { self.font_path = path; self.font_layout = font_layout; self @@ -468,7 +470,7 @@ impl<'a> RootInitializer<'a> { match self.font_dimension { FontDimensions(horizontal, vertical) => { - Root::set_custom_font(&std::path::Path::new(self.font_path), + Root::set_custom_font(self.font_path, self.font_layout, self.font_type, horizontal, vertical) }