forked from karx/catbox
added the ability to make sprite primitives, will add onto this later
This commit is contained in:
parent
f7c2053a6d
commit
64b484f7c9
|
@ -25,7 +25,7 @@ zip-extract = "0.1.2"
|
||||||
tempfile = "3.4.0"
|
tempfile = "3.4.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["audio"]
|
default = ["audio", "sdl2/gfx"]
|
||||||
static = ["sdl2/static-link", "sdl2/bundled"]
|
static = ["sdl2/static-link", "sdl2/bundled"]
|
||||||
audio = ["dep:rodio"]
|
audio = ["dep:rodio"]
|
||||||
vulkan = ["dep:vulkano"]
|
vulkan = ["dep:vulkano"]
|
||||||
|
|
|
@ -334,8 +334,7 @@ pub fn draw_text<S: AsRef<str>, I: Into<Vec2Int>>(
|
||||||
/// Representation of the mouse state.
|
/// Representation of the mouse state.
|
||||||
pub struct MouseRepr {
|
pub struct MouseRepr {
|
||||||
pub buttons: Vec<MouseButton>,
|
pub buttons: Vec<MouseButton>,
|
||||||
pub x: i32,
|
pub pos: Vec2Int
|
||||||
pub y: i32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Representation of the keyboard state.
|
/// Representation of the keyboard state.
|
||||||
|
@ -358,8 +357,7 @@ pub fn get_mouse_state(ctx: &mut Context) -> MouseRepr {
|
||||||
|
|
||||||
MouseRepr {
|
MouseRepr {
|
||||||
buttons: mouse.pressed_mouse_buttons().collect(),
|
buttons: mouse.pressed_mouse_buttons().collect(),
|
||||||
x: mouse.x(),
|
pos: Vec2Int::new(mouse.x(), mouse.y())
|
||||||
y: mouse.y(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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!`
|
/// 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.
|
/// Don't forget to call [`draw()`](Self::draw()) after this.
|
||||||
|
|
Loading…
Reference in a new issue