added the ability to make sprite primitives, will add onto this later

This commit is contained in:
gallant 2023-05-17 10:29:05 -05:00
parent f7c2053a6d
commit 64b484f7c9
3 changed files with 25 additions and 5 deletions

View file

@ -25,7 +25,7 @@ zip-extract = "0.1.2"
tempfile = "3.4.0"
[features]
default = ["audio"]
default = ["audio", "sdl2/gfx"]
static = ["sdl2/static-link", "sdl2/bundled"]
audio = ["dep:rodio"]
vulkan = ["dep:vulkano"]

View file

@ -334,8 +334,7 @@ pub fn draw_text<S: AsRef<str>, I: Into<Vec2Int>>(
/// Representation of the mouse state.
pub struct MouseRepr {
pub buttons: Vec<MouseButton>,
pub x: i32,
pub y: i32,
pub pos: Vec2Int
}
/// Representation of the keyboard state.
@ -358,8 +357,7 @@ pub fn get_mouse_state(ctx: &mut Context) -> MouseRepr {
MouseRepr {
buttons: mouse.pressed_mouse_buttons().collect(),
x: mouse.x(),
y: mouse.y(),
pos: Vec2Int::new(mouse.x(), mouse.y())
}
}

View file

@ -47,6 +47,28 @@ impl Sprite {
})
}
pub fn rect_sprite<C: sdl2::gfx::primitives::ToColor>(x: i32, y: i32,width: u32, height: u32, color: C) -> Result<Self> {
let (rmask,gmask,bmask,amask) = color.as_rgba();
let mask = sdl2::pixels::PixelMasks {
bpp: 32,
rmask: rmask.into(),
gmask: gmask.into(),
bmask: bmask.into(),
amask: amask.into()
};
let surf = Surface::from_pixelmasks(width, height, mask).unwrap();
surf.rect().set_y(y);
surf.rect().set_x(x);
Ok(Self{
rect: surf.rect(),
surf,
angle: 0.0,
})
}
/// Create a new sprite using a slice of bytes, like what is returned from `include_bytes!`
///
/// Don't forget to call [`draw()`](Self::draw()) after this.