[−][src]Struct tesserae::Graphic
A Graphic
is an image composed of many Tile
s in a rectangle.
The type parameter T
determines whether the Graphic maintains
an SDL Texture
for drawing the graphic to screen. A Graphic<()>
is a dummy graphic with no texture, useful only for graphics that
don't get drawn to the screen.
A Graphic<Texture>
contains a cached
SDL texture and features additional methods for refreshing
the texture cache and drawing the texture to screen. Any time the
tiles in the graphic are changed, a dirty
flag is set to true.
This can be set back to false again by calling update_texture
,
which redraws the graphic to the texture.
Methods
impl Graphic<()>
[src]
pub fn load_file<P: AsRef<Path>>(path: P) -> Result<Graphic<()>>
[src]
Load a graphic from a file given its path. Sugar for using
load_from
with a freshly-opened File
:
Graphic::load_file(path) // same as Graphic::load_from(File::open(path)?)
pub fn load_from<R: Read>(input: R) -> Result<Graphic<()>>
[src]
Load a graphic from any instance of the Read
trait.
Commonly used for loading files statically bundled into the binary with
include_bytes!
.
let g = Graphic::load_from(Cursor::new(&include_bytes!("file")[..]))
pub fn solid(width: u32, height: u32, tile: Tile) -> Graphic<()>
[src]
Create a graphic comprised of the given tile repeated width
times height
times.
pub fn blank(width: u32, height: u32) -> Graphic<()>
[src]
Create a blank graphic of the given size, with the tile index 0, fully transparent colors.
Graphic::blank(8,12) // same as Graphic::solid(8,12,Default::default())
pub fn textured<'r, T>(
&self,
texture_creator: &'r TextureCreator<T>
) -> Graphic<Texture<'r>>
[src]
&self,
texture_creator: &'r TextureCreator<T>
) -> Graphic<Texture<'r>>
A method to attach an SDL texture, converting the graphic from an unrenderable one to a renderable one. Commonly used straight after creation, like so:
let g = Graphics::load_file("path")?.textured(texture_creator);
Note that the texture has not rendered yet (and is marked as dirty), so typically you would want to call update_texture
and provide a tileset before drawing to screen.
impl<T> Graphic<T>
[src]
pub fn save<W: Write>(&self, file: &mut W) -> Result<()>
[src]
Save a graphic to some instance of Write
(such as a file), using the same file format used in load_from
.
pub fn width(&self) -> u32
[src]
The width of the graphic in tiles.
pub fn height(&self) -> u32
[src]
The height of the graphic in tiles.
pub fn get_tile(&self, x: u32, y: u32) -> Tile
[src]
Return the tile at the given location in the graphic. Equivalent to indexing, but returns a blank tile if out of bounds instead of a panic.
pub fn set_tile(&mut self, x: u32, y: u32, tile: Tile)
[src]
Change the tile at position (x,y)
in the graphic.
Equivalent to assigning to an index, but does nothing if the tile
is out of bounds rather than panic.
pub fn color_tile(&mut self, x: u32, y: u32, fg: Color, bg: Color)
[src]
Set the colors of the given tile in the graphic but leave the tile index unchanged.
pub fn draw_rect(&mut self, x: u32, y: u32, width: u32, height: u32, tile: Tile)
[src]
Draw a filled rectangle starting at (x,y)
in the top-left of dimensions
width
times height
, consisting of the tile tile
.
pub fn color_rect(
&mut self,
x: u32,
y: u32,
width: u32,
height: u32,
fg: Color,
bg: Color
)
[src]
&mut self,
x: u32,
y: u32,
width: u32,
height: u32,
fg: Color,
bg: Color
)
Change the foreground and background colors of all tiles in the
rectangle starting at (x,y)
in the top-left of dimensions
width
times height
, but leaving the tile index unchanged.
pub fn draw_text(
&mut self,
string: &str,
tile_set: &TileSet,
x: u32,
y: u32,
fg: Color,
bg: Color
)
[src]
&mut self,
string: &str,
tile_set: &TileSet,
x: u32,
y: u32,
fg: Color,
bg: Color
)
Draw text using one tile per character moving leftward, starting at (x,y)
, according to the character map built-in to the
tile set. If it overflows the end of the graphic, the text is truncated.
pub fn copy_tiles_from<U>(
&mut self,
other: &Graphic<U>,
src_x: u32,
src_y: u32,
src_w: u32,
src_h: u32,
dest_x: u32,
dest_y: u32
)
[src]
&mut self,
other: &Graphic<U>,
src_x: u32,
src_y: u32,
src_w: u32,
src_h: u32,
dest_x: u32,
dest_y: u32
)
Copy tiles from another Graphic
to this one. Every tile in the other
graphic in the rectangle of size src_w
times src_height
starting at (src_x,src_y)
in the top-left is copied to this graphic starting at (dest_x, dest_y)
.
pub fn copy_all_tiles_from<U>(
&mut self,
other: &Graphic<U>,
dest_x: u32,
dest_y: u32
)
[src]
&mut self,
other: &Graphic<U>,
dest_x: u32,
dest_y: u32
)
Copy all tiles from another Graphic
to this one. Every tile in the other
graphic is copied to this graphic starting at (dest_x, dest_y)
.
impl<'r> Graphic<Texture<'r>>
[src]
pub fn load_file_textured<P: AsRef<Path>, T>(
path: P,
texture_creator: &'r TextureCreator<T>
) -> Result<Graphic<Texture<'r>>>
[src]
path: P,
texture_creator: &'r TextureCreator<T>
) -> Result<Graphic<Texture<'r>>>
A shortcut to load a file and associate a texture in one step. Equivalent to using load_file
and then textured
.
pub fn mark_dirty(&mut self)
[src]
Mark the texture as needing updating (via update_texture
). This is useful if you need to change tile sets.
pub fn update_texture(&mut self, tile_set: &TileSet)
[src]
If the dirty flag is true, draw each tile in the graphic to the internal texture using the provided tile set.
pub fn draw<P: Into<Point>, T: RenderTarget>(
&self,
canvas: &mut Canvas<T>,
position: P
)
[src]
&self,
canvas: &mut Canvas<T>,
position: P
)
Draw the graphic to the screen at the provided position.
Note that you may wish to call update_texture
and provide a tile set first, as this simply draws the
cached texture.
pub fn texture(&self) -> &Texture
[src]
Get the SDL texture associated with this graphic.
Trait Implementations
impl<T: Clone> Clone for Graphic<T>
[src]
impl<T> Index<(u32, u32)> for Graphic<T>
[src]
type Output = Tile
The returned type after indexing.
fn index(&self, index: (u32, u32)) -> &Tile
[src]
impl<T> IndexMut<(u32, u32)> for Graphic<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Graphic<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Graphic<T> where
T: Send,
T: Send,
impl<T> Sync for Graphic<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Graphic<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Graphic<T> where
T: UnwindSafe,
T: UnwindSafe,
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>,