Trait tcod::console::Console
[−]
[src]
pub trait Console: AsNative<TCOD_console_t> { fn get_alignment(&self) -> TextAlignment { ... } fn set_alignment(&mut self, alignment: TextAlignment) { ... } fn set_key_color(&mut self, color: Color) { ... } fn width(&self) -> i32 { ... } fn height(&self) -> i32 { ... } fn get_default_background(&mut self) -> Color { ... } fn set_default_background(&mut self, color: Color) { ... } fn set_default_foreground(&mut self, color: Color) { ... } fn get_char_background(&self, x: i32, y: i32) -> Color { ... } fn get_char_foreground(&self, x: i32, y: i32) -> Color { ... } fn get_background_flag(&self) -> BackgroundFlag { ... } fn set_background_flag(&mut self, background_flag: BackgroundFlag) { ... } fn get_char(&self, x: i32, y: i32) -> char { ... } fn set_char(&mut self, x: i32, y: i32, c: char) { ... } fn set_char_background(&mut self,
x: i32,
y: i32,
color: Color,
background_flag: BackgroundFlag) { ... } fn set_char_foreground(&mut self, x: i32, y: i32, color: Color) { ... } fn put_char(&mut self,
x: i32,
y: i32,
glyph: char,
background_flag: BackgroundFlag) { ... } fn put_char_ex(&mut self,
x: i32,
y: i32,
glyph: char,
foreground: Color,
background: Color) { ... } fn clear(&mut self) { ... } fn print<T>(&mut self, x: i32, y: i32, text: T) where Self: Sized, T: AsRef<[u8]> + TcodString { ... } fn print_rect<T>(&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
text: T) where Self: Sized, T: AsRef<[u8]> + TcodString { ... } fn print_ex<T>(&mut self,
x: i32,
y: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T) where Self: Sized, T: AsRef<[u8]> + TcodString { ... } fn print_rect_ex<T>(&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T) where Self: Sized, T: AsRef<[u8]> + TcodString { ... } fn get_height_rect<T>(&self,
x: i32,
y: i32,
width: i32,
height: i32,
text: T)
-> i32 where Self: Sized, T: AsRef<[u8]> + TcodString { ... } fn rect(&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag) { ... } fn horizontal_line(&mut self,
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag) { ... } fn vertical_line(&mut self,
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag) { ... } fn print_frame<T>(&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag,
title: Option<T>) where Self: Sized, T: AsRef<str> { ... } }
Defines the common functionality between Root
and Offscreen
consoles
Examples
Printing text with explicit alignment:
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."); root.print_ex(78, 1, BackgroundFlag::None, TextAlignment::Right, "Text aligned to right."); root.print_ex(40, 15, BackgroundFlag::None, TextAlignment::Center, "And this bit of text is centered."); root.print_ex(40, 19, BackgroundFlag::None, TextAlignment::Center, "Press any key to quit.");
Provided Methods
fn get_alignment(&self) -> TextAlignment
Returns the default text alignment for the Console
instance. For all the possible
text alignment options, see the documentation for
TextAlignment.
fn set_alignment(&mut self, alignment: TextAlignment)
Sets the default text alignment for the console. For all the possible text alignment options, see the documentation for TextAlignment.
fn set_key_color(&mut self, color: Color)
Sets a key color that will be ignored when blitting the contents of this console onto an other (essentially a transparent background color).
fn width(&self) -> i32
Returns the width of the console in characters.
fn height(&self) -> i32
Returns the height of the console in characters.
fn get_default_background(&mut self) -> Color
Return the console's default background color. This is used in
several other methods, like: clear
, put_char
, etc.
fn set_default_background(&mut self, color: Color)
Sets the console's default background color. This is used in several other methods,
like: clear
, put_char
, etc.
fn set_default_foreground(&mut self, color: Color)
Sets the console's default foreground color. This is used in several printing functions.
fn get_char_background(&self, x: i32, y: i32) -> Color
Returns the background color of the cell at the specified coordinates.
fn get_char_foreground(&self, x: i32, y: i32) -> Color
Returns the foreground color of the cell at the specified coordinates.
fn get_background_flag(&self) -> BackgroundFlag
Returns the console's current background flag. For a detailed explanation of the possible values, see BackgroundFlag.
fn set_background_flag(&mut self, background_flag: BackgroundFlag)
Sets the console's current background flag. For a detailed explanation of the possible values, see BackgroundFlag.
fn get_char(&self, x: i32, y: i32) -> char
Returns the ASCII value of the cell located at x, y
fn set_char(&mut self, x: i32, y: i32, c: char)
Modifies the ASCII value of the cell located at x, y
.
fn set_char_background(&mut self,
x: i32,
y: i32,
color: Color,
background_flag: BackgroundFlag)
x: i32,
y: i32,
color: Color,
background_flag: BackgroundFlag)
Changes the background color of the specified cell
fn set_char_foreground(&mut self, x: i32, y: i32, color: Color)
Changes the foreground color of the specified cell
fn put_char(&mut self,
x: i32,
y: i32,
glyph: char,
background_flag: BackgroundFlag)
x: i32,
y: i32,
glyph: char,
background_flag: BackgroundFlag)
This function modifies every property of the given cell:
- Updates its background color according to the console's default and
background_flag
, see BackgroundFlag. - Updates its foreground color based on the default color set in the console
- Sets its ASCII value to
glyph
fn put_char_ex(&mut self,
x: i32,
y: i32,
glyph: char,
foreground: Color,
background: Color)
x: i32,
y: i32,
glyph: char,
foreground: Color,
background: Color)
Updates every propert of the given cell using explicit colors for the background and foreground.
fn clear(&mut self)
Clears the console with its default background color
fn print<T>(&mut self, x: i32, y: i32, text: T) where Self: Sized, T: AsRef<[u8]> + TcodString
Prints the text at the specified location. The position of the x
and y
coordinates depend on the TextAlignment set in the console:
TextAlignment::Left
: leftmost character of the stringTextAlignment::Center
: center character of the stingTextAlignment::Right
: rightmost character of the string
fn print_rect<T>(&mut self, x: i32, y: i32, width: i32, height: i32, text: T) where Self: Sized, T: AsRef<[u8]> + TcodString
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_ex<T>(&mut self,
x: i32,
y: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T) where Self: Sized, T: AsRef<[u8]> + TcodString
x: i32,
y: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T) where Self: Sized, T: AsRef<[u8]> + TcodString
Prints the text at the specified location with an explicit BackgroundFlag and TextAlignment.
fn print_rect_ex<T>(&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T) where Self: Sized, T: AsRef<[u8]> + TcodString
x: i32,
y: i32,
width: i32,
height: i32,
background_flag: BackgroundFlag,
alignment: TextAlignment,
text: T) where Self: Sized, T: AsRef<[u8]> + TcodString
Combines the functions of print_ex
and print_rect
fn get_height_rect<T>(&self,
x: i32,
y: i32,
width: i32,
height: i32,
text: T)
-> i32 where Self: Sized, T: AsRef<[u8]> + TcodString
x: i32,
y: i32,
width: i32,
height: i32,
text: T)
-> i32 where Self: Sized, T: AsRef<[u8]> + TcodString
Compute the height of a wrapped text printed using print_rect
or print_rect_ex
.
fn rect(&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag)
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag)
Fill a rectangle with the default background colour.
If clear
is true, set each cell's character to space (ASCII 32).
fn horizontal_line(&mut self,
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag)
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag)
Draw a horizontal line.
Uses tcod::chars::HLINE
(ASCII 196) as the line character and
console's default background and foreground colours.
fn vertical_line(&mut self,
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag)
x: i32,
y: i32,
length: i32,
background_flag: BackgroundFlag)
Draw a vertical line.
Uses tcod::chars::VLINE
(ASCII 179) as the line character and
console's default background and foreground colours.
fn print_frame<T>(&mut self,
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag,
title: Option<T>) where Self: Sized, T: AsRef<str>
x: i32,
y: i32,
width: i32,
height: i32,
clear: bool,
background_flag: BackgroundFlag,
title: Option<T>) where Self: Sized, T: AsRef<str>
Draw a window frame with an optional title.
Draws a rectangle (using the rect method) using the suplied background flag, then draws a rectangle with the console's default foreground colour.
If the title
is specified, it will be printed on top of the rectangle
using inverted colours.