[−][src]Struct console_engine::screen::Screen
Screen structure
A standalone structure that provides every drawing function that ConsoleEngine provides.
You can get the full content of the screen via the to_string method.
Implementations
impl Screen
[src]
Basic Usage :
use console_engine::pixel; use console_engine::screen::Screen; use console_engine::Color; fn main() { // create a screen of 20x11 characters let mut scr = screen::Screen::new(20,11); // draw some shapes and prints some text scr.rect(0,0, 19,10,pixel::pxl('#')); scr.fill_circle(5,5, 3, pixel::pxl_fg('*', Color::Blue)); scr.print(11,4, "Hello,"); scr.print(11,5, "World!"); // print the screen to the terminal println!("{}", scr.to_string()); }
pub fn new(width: u32, height: u32) -> Screen
[src]
Creates a new Screen object with the provided width and height.
pub fn new_empty(width: u32, height: u32) -> Screen
[src]
Creates a new empty Screen object with the provided widht and height
Makes sure to clear
or fill
it before drawing anything
pub fn new_fill(width: u32, height: u32, pixel: Pixel) -> Screen
[src]
Creates a new Screen object with the provided width and height filled with a specific Pixel
pub fn from_vec(vec: Vec<Pixel>, width: u32, height: u32) -> Screen
[src]
Creates a new Screen object with the provided Vec
pub fn from_string(
string: String,
fg: Color,
bg: Color,
width: u32,
height: u32
) -> Screen
[src]
string: String,
fg: Color,
bg: Color,
width: u32,
height: u32
) -> Screen
Creates a new Screen object with the provided String and colors fitting the width and height parameters. The String length must correspond to width*height
pub fn get_width(&self) -> u32
[src]
Get the screen width
pub fn get_height(&self) -> u32
[src]
Get the screen height
pub fn clear(&mut self)
[src]
Reset the screen to a blank state
pub fn fill(&mut self, pixel: Pixel)
[src]
pub fn check_empty(&mut self) -> bool
[src]
pub fn is_empty(&self) -> bool
[src]
pub fn print(&mut self, x: i32, y: i32, string: &str)
[src]
prints a string at the specified coordinates.
The string will be cropped if it reach the right border
usage:
screen.print(0,0, "Hello, world!"); screen.print(0, 4, format!("Score: {}", score).as_str());
pub fn print_fbg(&mut self, x: i32, y: i32, string: &str, fg: Color, bg: Color)
[src]
prints a string at the specified coordinates with the specified foreground and background color
The string will be cropped if it reach the right border
usage:
use console_engine::Color; // print "Hello, world" in blue on white background screen.print(0,0, "Hello, world!", Color::Blue, Color::White);
pub fn print_screen(&mut self, x: i32, y: i32, source: &Screen)
[src]
Prints another screen on specified coordinates. Useful when you want to manage several "subscreen"
usage:
use console_engine::pixel; use console_engine::screen::Screen; // create a new Screen struct and draw a square inside it let mut my_square = Screen::new(8,8); my_square.rect(0,0,7,7,pixel::pxl('#')); my_square.print(1,1,"square"); // prints the square in the main window at a specific location screen.print_screen(5,2, &my_square);
pub fn print_screen_alpha(
&mut self,
x: i32,
y: i32,
source: &Screen,
alpha_character: char
)
[src]
&mut self,
x: i32,
y: i32,
source: &Screen,
alpha_character: char
)
Prints another screen on specified coordinates, ignoring a specific character while printing Ignoring a character will behave like transparency
see print_screen for usage
pub fn h_line(
&mut self,
start_x: i32,
start_y: i32,
end_x: i32,
character: Pixel
)
[src]
&mut self,
start_x: i32,
start_y: i32,
end_x: i32,
character: Pixel
)
Optimized horizontal line drawing Automatically called by line if needed
pub fn v_line(
&mut self,
start_x: i32,
start_y: i32,
end_y: i32,
character: Pixel
)
[src]
&mut self,
start_x: i32,
start_y: i32,
end_y: i32,
character: Pixel
)
Optimized vertical line drawing Automatically called by line if needed
pub fn line(
&mut self,
start_x: i32,
start_y: i32,
end_x: i32,
end_y: i32,
character: Pixel
)
[src]
&mut self,
start_x: i32,
start_y: i32,
end_x: i32,
end_y: i32,
character: Pixel
)
draws a line of the provided character between two sets of coordinates
see: Bresenham's line algorithm
Note : Your line can start or end out of bounds. These pixels won't be drawn
usage:
use console_engine::pixel; // ... screen.line(0, 0, 9, 9, pixel::pxl('#'));
pub fn rect(
&mut self,
start_x: i32,
start_y: i32,
end_x: i32,
end_y: i32,
character: Pixel
)
[src]
&mut self,
start_x: i32,
start_y: i32,
end_x: i32,
end_y: i32,
character: Pixel
)
Draws a rectangle of the provided character between two sets of coordinates
usage:
use console_engine::pixel; // ... screen.rect(0, 0, 9, 9, pixel::pxl('#'));
pub fn fill_rect(
&mut self,
start_x: i32,
start_y: i32,
end_x: i32,
end_y: i32,
character: Pixel
)
[src]
&mut self,
start_x: i32,
start_y: i32,
end_x: i32,
end_y: i32,
character: Pixel
)
Fill a rectangle of the provided character between two sets of coordinates
usage:
use console_engine::pixel; // ... screen.fill_rect(0, 0, 9, 9, pixel::pxl('#'));
pub fn circle(&mut self, x: i32, y: i32, radius: u32, character: Pixel)
[src]
Draws a circle of the provided character at an x and y position with a radius see: olcPixelGameEngine Repository
usage:
use console_engine::pixel; // ... screen.circle(10, 10, 4, pixel::pxl('#'));
pub fn fill_circle(&mut self, x: i32, y: i32, radius: u32, character: Pixel)
[src]
Fill a circle of the provided character at an x and y position with a radius see: olcPixelGameEngine Repository
usage:
use console_engine::pixel; // ... screen.fill_circle(10, 10, 4, pixel::pxl('#'));
pub fn triangle(
&mut self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
x3: i32,
y3: i32,
character: Pixel
)
[src]
&mut self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
x3: i32,
y3: i32,
character: Pixel
)
Draws a triangle of the provided character using three sets of coordinates
usage:
use console_engine::pixel; // ... screen.triangle(8,8, 4,6, 9,2, pixel::pxl('#'));
pub fn fill_triangle(
&mut self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
x3: i32,
y3: i32,
character: Pixel
)
[src]
&mut self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
x3: i32,
y3: i32,
character: Pixel
)
Fill a triangle of the provided character using three sets of coordinates see: rustyPixelGameEngine Repository
usage:
use console_engine::pixel; // ... screen.fill_triangle(8,8, 4,6, 9,2, pixel::pxl('#'));
pub fn set_pxl(&mut self, x: i32, y: i32, character: Pixel)
[src]
sets the provided character in the specified coordinates out of bounds pixels will be ignored
usage:
use console_engine::pixel; // ... screen.set_pxl(3,8,pixel::pixel('o'));
pub fn get_pxl(&self, x: i32, y: i32) -> Result<Pixel, String>
[src]
Get the character stored at provided coordinates
usage:
if screen.get_pxl(3,8).unwrap().chr == 'o' { screen.print(0,0,"Found a 'o'"); }
pub fn resize(&mut self, new_width: u32, new_height: u32)
[src]
Resizes the screen to match the given width and height truncates the bottom and right side of the screen
usage:
screen.resize()
pub fn draw(&self)
[src]
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Screen
impl Send for Screen
impl Sync for Screen
impl Unpin for Screen
impl UnwindSafe for Screen
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,