Struct gemini_engine::elements::view::View
source · pub struct View {
pub width: usize,
pub height: usize,
pub background_char: ColChar,
/* private fields */
}
Expand description
The View struct is the canvas on which you will print all of your ViewElements. In normal use, you would clear the View, blit
all your ViewElements to it and then render. The following example demonstrates a piece of code that will render a View of width 9 and height 3, with a single Point in the middle
use gemini_engine::elements::{view::{Wrapping, ColChar}, View, Point, Vec2D};
fn main() {
let mut view = View::new(9, 3, ColChar::BACKGROUND);
let point = Point::new(Vec2D::new(4,1), ColChar::SOLID);
view.blit(&point, Wrapping::Panic);
view.display_render().unwrap();
}
Fields§
§width: usize
§height: usize
§background_char: ColChar
Implementations§
source§impl View
impl View
sourcepub fn new(width: usize, height: usize, background_char: ColChar) -> View
pub fn new(width: usize, height: usize, background_char: ColChar) -> View
Examples found in repository?
examples/quick-start.rs (line 10)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut view = View::new(40, 8, ColChar::BACKGROUND);
let mut point = Point::new(Vec2D { x: 10, y: 5 }, ColChar::SOLID);
loop {
view.clear();
point.pos.x += 1;
view.blit(&point, Wrapping::Wrap);
view.display_render().unwrap();
gameloop::sleep_fps(FPS, None);
}
}
More examples
examples/spinning-cube.rs (line 10)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn main() {
let mut frame_skip = false;
let mut view = View::new(350, 90, ColChar::BACKGROUND);
let mut viewport = Viewport::new(
Vec3D::new(0.0, 0.0, 6.0),
Vec3D::new(-0.5, 0.0, 0.0),
FOV,
Vec2D::new((view.width / 2) as isize, (view.height / 2) as isize),
);
let cube = Mesh3D::default_cube();
loop {
let now = gameloop::Instant::now();
view.clear();
viewport.rotation.y -= 0.05;
match frame_skip {
true => frame_skip = false,
false => {
viewport.blit_to(&mut view, vec![&cube], DisplayMode::Solid);
view.display_render().unwrap();
}
}
let elapsed = now.elapsed();
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
frame_skip = gameloop::sleep_fps(FPS, Some(elapsed));
}
}
pub fn size(&self) -> Vec2D
pub fn center(&self) -> Vec2D
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Examples found in repository?
examples/quick-start.rs (line 14)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut view = View::new(40, 8, ColChar::BACKGROUND);
let mut point = Point::new(Vec2D { x: 10, y: 5 }, ColChar::SOLID);
loop {
view.clear();
point.pos.x += 1;
view.blit(&point, Wrapping::Wrap);
view.display_render().unwrap();
gameloop::sleep_fps(FPS, None);
}
}
More examples
examples/spinning-cube.rs (line 23)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn main() {
let mut frame_skip = false;
let mut view = View::new(350, 90, ColChar::BACKGROUND);
let mut viewport = Viewport::new(
Vec3D::new(0.0, 0.0, 6.0),
Vec3D::new(-0.5, 0.0, 0.0),
FOV,
Vec2D::new((view.width / 2) as isize, (view.height / 2) as isize),
);
let cube = Mesh3D::default_cube();
loop {
let now = gameloop::Instant::now();
view.clear();
viewport.rotation.y -= 0.05;
match frame_skip {
true => frame_skip = false,
false => {
viewport.blit_to(&mut view, vec![&cube], DisplayMode::Solid);
view.display_render().unwrap();
}
}
let elapsed = now.elapsed();
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
frame_skip = gameloop::sleep_fps(FPS, Some(elapsed));
}
}
pub fn plot(&mut self, pos: Vec2D, c: ColChar, wrapping: Wrapping)
sourcepub fn blit<T: ViewElement>(&mut self, element: &T, wrapping: Wrapping)
pub fn blit<T: ViewElement>(&mut self, element: &T, wrapping: Wrapping)
Blit a ViewElement to the screen. This is usually done before rendering.
Examples found in repository?
examples/quick-start.rs (line 18)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut view = View::new(40, 8, ColChar::BACKGROUND);
let mut point = Point::new(Vec2D { x: 10, y: 5 }, ColChar::SOLID);
loop {
view.clear();
point.pos.x += 1;
view.blit(&point, Wrapping::Wrap);
view.display_render().unwrap();
gameloop::sleep_fps(FPS, None);
}
}
sourcepub fn display_render(&self) -> Result<()>
pub fn display_render(&self) -> Result<()>
Display the View. View implements the Display trait so you can display it how you wish, but this is intended to be the fastest way possible
Examples found in repository?
examples/quick-start.rs (line 19)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
fn main() {
let mut view = View::new(40, 8, ColChar::BACKGROUND);
let mut point = Point::new(Vec2D { x: 10, y: 5 }, ColChar::SOLID);
loop {
view.clear();
point.pos.x += 1;
view.blit(&point, Wrapping::Wrap);
view.display_render().unwrap();
gameloop::sleep_fps(FPS, None);
}
}
More examples
examples/spinning-cube.rs (line 31)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn main() {
let mut frame_skip = false;
let mut view = View::new(350, 90, ColChar::BACKGROUND);
let mut viewport = Viewport::new(
Vec3D::new(0.0, 0.0, 6.0),
Vec3D::new(-0.5, 0.0, 0.0),
FOV,
Vec2D::new((view.width / 2) as isize, (view.height / 2) as isize),
);
let cube = Mesh3D::default_cube();
loop {
let now = gameloop::Instant::now();
view.clear();
viewport.rotation.y -= 0.05;
match frame_skip {
true => frame_skip = false,
false => {
viewport.blit_to(&mut view, vec![&cube], DisplayMode::Solid);
view.display_render().unwrap();
}
}
let elapsed = now.elapsed();
println!(
"Elapsed: {:.2?}µs | Frame skip: {}",
elapsed.as_micros(),
frame_skip
);
frame_skip = gameloop::sleep_fps(FPS, Some(elapsed));
}
}
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for View
impl Send for View
impl Sync for View
impl Unpin for View
impl UnwindSafe for View
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more