diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index 85df2a55..2c0e5ac2 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -21,7 +21,9 @@ pub use sprites::{ pub use affine::AffineMatrixInstance; 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}; diff --git a/agb/src/display/object/unmanaged.rs b/agb/src/display/object/unmanaged.rs index 42f609fa..0edf1fea 100644 --- a/agb/src/display/object/unmanaged.rs +++ b/agb/src/display/object/unmanaged.rs @@ -1,5 +1,5 @@ mod attributes; mod object; -pub use attributes::AffineMode; +pub use attributes::{AffineMode, GraphicsMode}; pub use object::{OamIterator, OamSlot, OamUnmanaged, ObjectUnmanaged}; diff --git a/agb/src/display/object/unmanaged/attributes.rs b/agb/src/display/object/unmanaged/attributes.rs index 3f7426d4..a32554b0 100644 --- a/agb/src/display/object/unmanaged/attributes.rs +++ b/agb/src/display/object/unmanaged/attributes.rs @@ -20,7 +20,7 @@ impl Default for Attributes { a0: ObjectAttribute0::new( 0, ObjectMode::Disabled, - GraphicsMode::Normal, + GraphicsModeInternal::Normal, false, ColourMode::Four, u2::new(0), @@ -152,6 +152,28 @@ impl Attributes { 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)] @@ -166,7 +188,7 @@ enum ObjectMode { #[bitsize(2)] #[derive(TryFromBits, Clone, Copy, Debug, PartialEq, Eq, Default)] -enum GraphicsMode { +enum GraphicsModeInternal { #[default] Normal, AlphaBlending, @@ -190,7 +212,7 @@ mod attributes { pub(super) struct ObjectAttribute0 { pub y: u8, pub object_mode: ObjectMode, - pub graphics_mode: GraphicsMode, + pub graphics_mode: GraphicsModeInternal, pub mosaic: bool, pub colour_mode: ColourMode, pub shape: u2, diff --git a/agb/src/display/object/unmanaged/object.rs b/agb/src/display/object/unmanaged/object.rs index bcc36a4e..9a83b198 100644 --- a/agb/src/display/object/unmanaged/object.rs +++ b/agb/src/display/object/unmanaged/object.rs @@ -11,7 +11,7 @@ use crate::display::{ Priority, }; -use super::attributes::{AffineMode, Attributes}; +use super::attributes::{AffineMode, Attributes, GraphicsMode}; #[derive(Debug)] struct OamFrameModifyables { @@ -406,6 +406,13 @@ impl ObjectUnmanaged { 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)]