Skip to content

Add documentation for set_target_bitmap #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions allegro/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ pub struct Bitmap

impl Bitmap
{

/// This function is used to create a new Bitmap object.
/// Can be used to create a bitmap of w width and h height.
///
/// # Examples
/// ```
/// use allegro::*;
///
/// pub fn new_bitmap(core: &Core) {
/// let new_bitmap: Bitmap = match Bitmap::new(&core, 400, 200) {
/// Ok(v) => v,
/// Err(e) => panic!("Error loading new_bitmap"),
/// };
/// }
/// ```
pub fn new(_: &Core, w: i32, h: i32) -> Result<Bitmap, ()>
{
unsafe {
Expand All @@ -36,6 +51,24 @@ impl Bitmap
}
}

/// This function is used to load a bitmap file into a Bitmap object.
/// Takes a string path_to_map that points to a bitmap file.
///
/// NOTE: Be sure to initialize image addon before running the
/// load_bitmap function ex: ImageAddon::init(&core).unwrap();
///
/// // For a more complete example look at example/example.rs
/// # Examples
/// ```
/// use allegro::*;
///
/// pub fn load_bitmap(core: &Core, path_to_map: &str) {
/// let tileset_bitmap: Bitmap = match Bitmap::load(&core, path_to_map) {
/// Ok(v) => v,
/// Err(e) => panic!("Error loading tileset_bitmap"),
/// };
/// }
/// ```
pub fn load(_: &Core, filename: &str) -> Result<Bitmap, ()>
{
unsafe {
Expand Down
12 changes: 12 additions & 0 deletions allegro/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,18 @@ impl Core
unsafe { mem::transmute(al_get_new_bitmap_format() as u32) }
}


/// This function is used to set the target bitmap that allegro draws to.
/// # Examples
/// ```
/// // How to set target bitmap similar to al_set_target_bitmap
/// // For a more complete example look at example/example.rs
/// use allegro::*;
/// let core = Core::init().unwrap();
/// let bmp = Bitmap::new(&core, 400, 400).unwrap();
/// core.set_target_bitmap(Some(&bmp));
/// ```

pub fn set_target_bitmap<T: BitmapLike>(&self, bmp: Option<&T>)
{
unsafe {
Expand Down
Loading