[−][src]Struct console_engine::ConsoleEngine
Fields
frame_count: usize
The current frame count, publicly accessible
Methods
impl ConsoleEngine
[src]
Basic Usage :
use console_engine::pixel; use console_engine::termion::color; use console_engine::termion::event::Key; fn main() { // initializes a screen of 20x10 characters with a target of 3 frame per second // coordinates will range from [0,0] to [19,9] let mut engine = console_engine::ConsoleEngine::init(20, 10, 3); let value = 14; // main loop, be aware that you'll have to break it because ctrl+C is captured loop { engine.wait_frame(); // wait for next frame + capture inputs engine.clear_screen(); // reset the screen engine.line(0, 0, 19, 9, pixel::pxl('#')); // draw a line of '#' from [0,0] to [19,9] engine.print(0, 4, format!("Result: {}", value)); // prints some value at [0,4] engine.set_pxl(4, 0, pixel::pxl_fg('O', color::Cyan)); // write a majestic cyan 'O' at [4,0] if engine.is_key_pressed(Key::Char('q')) { // if the user presses 'q' : break; // exits app } engine.draw(); // draw the screen } }
pub fn init(width: u32, height: u32, target_fps: u32) -> ConsoleEngine
[src]
Initialize a screen of the provided width and height, and load the target FPS
pub fn init_fill(target_fps: u32) -> ConsoleEngine
[src]
Initialize a screen filling the entire terminal with the target FPS
pub fn init_fill_require(
width: u32,
height: u32,
target_fps: u32
) -> ConsoleEngine
[src]
width: u32,
height: u32,
target_fps: u32
) -> ConsoleEngine
Initialize a screen filling the entire terminal with the target FPS
Also check the terminal width and height and assert if the terminal has at least the asked size
pub fn scr_w(&self) -> u32
[src]
Get the screen width
pub fn scr_h(&self) -> u32
[src]
Get the screen height
pub fn clear_screen(&mut self)
[src]
Reset the screen to a blank state
pub fn print(&mut self, x: i32, y: i32, string: String)
[src]
prints a string at the specified coordinates.
The string will be cropped if it reach the right border
usage:
engine.print(0,0, String::from("Hello, world!")); engine.print(0, 4, format!("Score: {}", score));
pub fn print_fbg<C1: Color + Clone, C2: Color + Clone>(
&mut self,
x: i32,
y: i32,
string: String,
fg: C1,
bg: C2
)
[src]
&mut self,
x: i32,
y: i32,
string: String,
fg: C1,
bg: C2
)
prints a string at the specified coordinates with the specified foreground and background color
The string will automatically overlaps if it reach the right border
usage
// print "Hello, world" in blue on white background engine.print(0,0, String::from("Hello, world!"), color::Blue, color::White);
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; // ... engine.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; // ... engine.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; // ... engine.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; // ... engine.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; // ... engine.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; // ... engine.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; // ... engine.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; // ... engine.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 engine.get_pxl(3,8).unwrap().chr == 'o' { engine.print(0,0,"Found a 'o'"); }
pub fn draw(&mut self)
[src]
Draw the screen in the terminal
For best results, use it once per frame
usage:
engine.print(0,0,String::from("Hello, world!")); // <- prints "Hello, world!" in 'screen' memory engine.draw(); // display 'screen' memory to the user's terminal
pub fn wait_frame(&mut self)
[src]
Pause the execution until the next frame need to be rendered
Internally gets user's input for the next frame
usage:
// initializes a screen with a 10x10 screen and targetting 30 fps let mut engine = console_engine::ConsoleEngine::init(10, 10, 30); loop { engine.wait_frame(); // wait for next frame // do your stuff }
pub fn check_resize(&mut self)
[src]
Check and resize the terminal if needed. Note that the resize will occur but there is no check yet if the terminal is smaller than the required size provided in the init() function.
usage:
// initializes a screen filling the terminal let mut engine = console_engine::ConsoleEngine::init_fill(30); loop { engine.wait_frame(); // wait for next frame engine.check_resize(); // resize the terminal if its size has changed // do your stuff }
pub fn is_key_pressed(&self, key: Key) -> bool
[src]
checks whenever a key is pressed (first frame held only)
usage:
loop { engine.wait_frame(); // wait for next frame + captures input if engine.is_key_pressed(Key::Char('q')) { break; // exits app } }
pub fn is_key_held(&self, key: Key) -> bool
[src]
checks whenever a key is held down
usage:
loop { engine.wait_frame(); // wait for next frame + captures input if engine.is_key_held(Key::Char('8')) && pos_y > 0 { pos_y -= 1; // move position upward } }
pub fn is_key_released(&self, key: Key) -> bool
[src]
checks whenever a key has been released (first frame released)
usage:
if engine.is_key_held(Key::Char('h')) { engine.clear_screen(); engine.print(0,0,"Please don't hold this button."); engine.draw(); while !engine.is_key_released(Key::Char('h')) { engine.wait_frame(); // refresh button's states } }
pub fn get_mouse_press(&self, button: MouseButton) -> Option<(u32, u32)>
[src]
Give the mouse's terminal coordinates if the provided button has been pressed
usage :
// prints a 'P' where the mouse's left button has been pressed let mouse_pos = engine.get_mouse_press(termion::event::MouseButton::Left); if mouse_pos.is_some() { let mouse_pos = mouse_pos.unwrap(); engine.set_pxl(mouse_pos.0 as i32, mouse_pos.1 as i32, pixel::pxl('P')); }
pub fn get_mouse_held(&self) -> Option<(u32, u32)>
[src]
Give the mouse's terminal coordinates if a button is held on the mouse
usage :
// prints a 'H' where the mouse is currently held let mouse_pos = engine.get_mouse_held(); if mouse_pos.is_some() { let mouse_pos = mouse_pos.unwrap(); engine.set_pxl(mouse_pos.0 as i32, mouse_pos.1 as i32, pixel::pxl('H')); }
pub fn get_mouse_released(&self) -> Option<(u32, u32)>
[src]
Give the mouse's terminal coordinates if a button has been released on the mouse
usage :
// prints a 'R' where the mouse has been released let mouse_pos = engine.get_mouse_held(); if mouse_pos.is_some() { let mouse_pos = mouse_pos.unwrap(); engine.set_pxl(mouse_pos.0 as i32, mouse_pos.1 as i32, pixel::pxl('H')); }
Trait Implementations
impl Drop for ConsoleEngine
[src]
Auto Trait Implementations
impl !RefUnwindSafe for ConsoleEngine
impl Send for ConsoleEngine
impl !Sync for ConsoleEngine
impl Unpin for ConsoleEngine
impl !UnwindSafe for ConsoleEngine
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, 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>,