expose graphics mode

This commit is contained in:
Corwin 2024-06-11 17:50:22 +01:00
parent 062eb1154e
commit fed560b41b
No known key found for this signature in database
4 changed files with 37 additions and 6 deletions

View file

@ -21,7 +21,9 @@ pub use sprites::{
pub use affine::AffineMatrixInstance; pub use affine::AffineMatrixInstance;
pub use managed::{OamManaged, Object}; pub use managed::{OamManaged, Object};
pub use unmanaged::{AffineMode, OamIterator, OamSlot, OamUnmanaged, ObjectUnmanaged}; pub use unmanaged::{
AffineMode, GraphicsMode, OamIterator, OamSlot, OamUnmanaged, ObjectUnmanaged,
};
pub use font::{ChangeColour, ObjectTextRender, TextAlignment}; pub use font::{ChangeColour, ObjectTextRender, TextAlignment};

View file

@ -1,5 +1,5 @@
mod attributes; mod attributes;
mod object; mod object;
pub use attributes::AffineMode; pub use attributes::{AffineMode, GraphicsMode};
pub use object::{OamIterator, OamSlot, OamUnmanaged, ObjectUnmanaged}; pub use object::{OamIterator, OamSlot, OamUnmanaged, ObjectUnmanaged};

View file

@ -20,7 +20,7 @@ impl Default for Attributes {
a0: ObjectAttribute0::new( a0: ObjectAttribute0::new(
0, 0,
ObjectMode::Disabled, ObjectMode::Disabled,
GraphicsMode::Normal, GraphicsModeInternal::Normal,
false, false,
ColourMode::Four, ColourMode::Four,
u2::new(0), u2::new(0),
@ -152,6 +152,28 @@ impl Attributes {
self self
} }
pub fn set_graphics_mode(&mut self, mode: GraphicsMode) -> &mut Self {
self.a0.set_graphics_mode(match mode {
GraphicsMode::Normal => GraphicsModeInternal::Normal,
GraphicsMode::AlphaBlending => GraphicsModeInternal::AlphaBlending,
GraphicsMode::Window => GraphicsModeInternal::Window,
});
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
/// Graphics modes control how it gets rendered
pub enum GraphicsMode {
#[default]
/// The sprite rendered as you expect
Normal,
/// This object is part of blending
AlphaBlending,
/// This object is a mask of the object window
Window,
} }
#[bitsize(2)] #[bitsize(2)]
@ -166,7 +188,7 @@ enum ObjectMode {
#[bitsize(2)] #[bitsize(2)]
#[derive(TryFromBits, Clone, Copy, Debug, PartialEq, Eq, Default)] #[derive(TryFromBits, Clone, Copy, Debug, PartialEq, Eq, Default)]
enum GraphicsMode { enum GraphicsModeInternal {
#[default] #[default]
Normal, Normal,
AlphaBlending, AlphaBlending,
@ -190,7 +212,7 @@ mod attributes {
pub(super) struct ObjectAttribute0 { pub(super) struct ObjectAttribute0 {
pub y: u8, pub y: u8,
pub object_mode: ObjectMode, pub object_mode: ObjectMode,
pub graphics_mode: GraphicsMode, pub graphics_mode: GraphicsModeInternal,
pub mosaic: bool, pub mosaic: bool,
pub colour_mode: ColourMode, pub colour_mode: ColourMode,
pub shape: u2, pub shape: u2,

View file

@ -11,7 +11,7 @@ use crate::display::{
Priority, Priority,
}; };
use super::attributes::{AffineMode, Attributes}; use super::attributes::{AffineMode, Attributes, GraphicsMode};
#[derive(Debug)] #[derive(Debug)]
struct OamFrameModifyables { struct OamFrameModifyables {
@ -406,6 +406,13 @@ impl ObjectUnmanaged {
self self
} }
/// Sets the graphics mode of the object
pub fn set_graphics_mode(&mut self, mode: GraphicsMode) -> &mut Self {
self.attributes.set_graphics_mode(mode);
self
}
} }
#[cfg(test)] #[cfg(test)]