pub struct MovableWindow { /* private fields */ }
Expand description

A window that can be moved

Implementations§

source§

impl MovableWindow

source

pub fn enable(&mut self) -> &mut Self

Enables the window, must call Windows::commit for this change to be seen. If a window is not enabled it will not have an effect on the display.

Examples found in repository?
examples/windows.rs (line 31)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fn main(mut gba: agb::Gba) -> ! {
    let (gfx, mut vram) = gba.display.video.tiled0();

    let mut map = gfx.background(
        agb::display::Priority::P0,
        RegularBackgroundSize::Background32x32,
        TileFormat::FourBpp,
    );
    let mut window = gba.display.window.get();
    window
        .win_in(WinIn::Win0)
        .set_background_enable(map.background(), true)
        .set_position(&Rect::new((10, 10).into(), (64, 64).into()))
        .enable();

    window
        .win_out()
        .enable()
        .set_background_enable(map.background(), true)
        .set_blend_enable(true);

    example_logo::display_logo(&mut map, &mut vram);

    let mut blend = gba.display.blend.get();

    blend
        .set_background_enable(Layer::Top, map.background(), true)
        .set_backdrop_enable(Layer::Bottom, true)
        .set_blend_mode(BlendMode::Normal);

    let mut pos: Vector2D<FNum> = (10, 10).into();
    let mut velocity: Vector2D<FNum> = Vector2D::new(1.into(), 1.into());

    let mut blend_amount: Num<i32, 8> = num!(0.5);
    let mut blend_velocity: Num<i32, 8> = Num::new(1) / 128;

    let vblank = VBlank::get();

    loop {
        pos += velocity;

        if pos.x.floor() > WIDTH - 64 || pos.x.floor() < 0 {
            velocity.x *= -1;
        }

        if pos.y.floor() > HEIGHT - 64 || pos.y.floor() < 0 {
            velocity.y *= -1;
        }

        blend_amount += blend_velocity;
        if blend_amount > num!(0.75) || blend_amount < num!(0.25) {
            blend_velocity *= -1;
        }

        blend_amount = blend_amount.clamp(0.into(), 1.into());

        blend.set_blend_weight(Layer::Top, blend_amount.try_change_base().unwrap());

        window
            .win_in(WinIn::Win0)
            .set_position(&Rect::new(pos.floor(), (64, 64).into()));

        vblank.wait_for_vblank();
        window.commit();
        blend.commit();
    }
}
source

pub fn disable(&mut self) -> &mut Self

Disables the window, must call Windows::commit for this change to be seen.

source

pub fn reset(&mut self) -> &mut Self

Resets the window to it’s default state, must call Windows::commit for this change to be seen. The default state is the window disabled with nothing rendered and represents a 0x0 rectangle at (0, 0).

source

pub fn set_blend_enable(&mut self, blend: bool) -> &mut Self

Sets whether the blend is enabled inside of this window, must call Windows::commit for this change to be seen.

source

pub fn set_background_enable( &mut self, back: BackgroundID, enable: bool ) -> &mut Self

Sets whether the given background will be rendered inside this window, must call Windows::commit for this change to be seen.

Examples found in repository?
examples/windows.rs (line 29)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fn main(mut gba: agb::Gba) -> ! {
    let (gfx, mut vram) = gba.display.video.tiled0();

    let mut map = gfx.background(
        agb::display::Priority::P0,
        RegularBackgroundSize::Background32x32,
        TileFormat::FourBpp,
    );
    let mut window = gba.display.window.get();
    window
        .win_in(WinIn::Win0)
        .set_background_enable(map.background(), true)
        .set_position(&Rect::new((10, 10).into(), (64, 64).into()))
        .enable();

    window
        .win_out()
        .enable()
        .set_background_enable(map.background(), true)
        .set_blend_enable(true);

    example_logo::display_logo(&mut map, &mut vram);

    let mut blend = gba.display.blend.get();

    blend
        .set_background_enable(Layer::Top, map.background(), true)
        .set_backdrop_enable(Layer::Bottom, true)
        .set_blend_mode(BlendMode::Normal);

    let mut pos: Vector2D<FNum> = (10, 10).into();
    let mut velocity: Vector2D<FNum> = Vector2D::new(1.into(), 1.into());

    let mut blend_amount: Num<i32, 8> = num!(0.5);
    let mut blend_velocity: Num<i32, 8> = Num::new(1) / 128;

    let vblank = VBlank::get();

    loop {
        pos += velocity;

        if pos.x.floor() > WIDTH - 64 || pos.x.floor() < 0 {
            velocity.x *= -1;
        }

        if pos.y.floor() > HEIGHT - 64 || pos.y.floor() < 0 {
            velocity.y *= -1;
        }

        blend_amount += blend_velocity;
        if blend_amount > num!(0.75) || blend_amount < num!(0.25) {
            blend_velocity *= -1;
        }

        blend_amount = blend_amount.clamp(0.into(), 1.into());

        blend.set_blend_weight(Layer::Top, blend_amount.try_change_base().unwrap());

        window
            .win_in(WinIn::Win0)
            .set_position(&Rect::new(pos.floor(), (64, 64).into()));

        vblank.wait_for_vblank();
        window.commit();
        blend.commit();
    }
}
source

pub fn set_object_enable(&mut self, obj: bool) -> &mut Self

Sets whether objects will be rendered inside this window, must call Windows::commit for this change to be seen.

source

pub fn set_position_u8(&mut self, rect: Rect<u8>) -> &mut Self

Sets the area of what is inside the window using [u8] representation, which is closest to what the GBA uses. Most of the time MovableWindow::set_position should be used.

source

pub fn set_position(&mut self, rect: &Rect<i32>) -> &mut Self

Sets the position of the area that is inside the window.

Examples found in repository?
examples/windows.rs (line 30)
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
fn main(mut gba: agb::Gba) -> ! {
    let (gfx, mut vram) = gba.display.video.tiled0();

    let mut map = gfx.background(
        agb::display::Priority::P0,
        RegularBackgroundSize::Background32x32,
        TileFormat::FourBpp,
    );
    let mut window = gba.display.window.get();
    window
        .win_in(WinIn::Win0)
        .set_background_enable(map.background(), true)
        .set_position(&Rect::new((10, 10).into(), (64, 64).into()))
        .enable();

    window
        .win_out()
        .enable()
        .set_background_enable(map.background(), true)
        .set_blend_enable(true);

    example_logo::display_logo(&mut map, &mut vram);

    let mut blend = gba.display.blend.get();

    blend
        .set_background_enable(Layer::Top, map.background(), true)
        .set_backdrop_enable(Layer::Bottom, true)
        .set_blend_mode(BlendMode::Normal);

    let mut pos: Vector2D<FNum> = (10, 10).into();
    let mut velocity: Vector2D<FNum> = Vector2D::new(1.into(), 1.into());

    let mut blend_amount: Num<i32, 8> = num!(0.5);
    let mut blend_velocity: Num<i32, 8> = Num::new(1) / 128;

    let vblank = VBlank::get();

    loop {
        pos += velocity;

        if pos.x.floor() > WIDTH - 64 || pos.x.floor() < 0 {
            velocity.x *= -1;
        }

        if pos.y.floor() > HEIGHT - 64 || pos.y.floor() < 0 {
            velocity.y *= -1;
        }

        blend_amount += blend_velocity;
        if blend_amount > num!(0.75) || blend_amount < num!(0.25) {
            blend_velocity *= -1;
        }

        blend_amount = blend_amount.clamp(0.into(), 1.into());

        blend.set_blend_weight(Layer::Top, blend_amount.try_change_base().unwrap());

        window
            .win_in(WinIn::Win0)
            .set_position(&Rect::new(pos.floor(), (64, 64).into()));

        vblank.wait_for_vblank();
        window.commit();
        blend.commit();
    }
}

Auto Trait Implementations§

§

impl RefUnwindSafe for MovableWindow

§

impl Send for MovableWindow

§

impl Sync for MovableWindow

§

impl Unpin for MovableWindow

§

impl UnwindSafe for MovableWindow

Blanket Implementations§

§

impl<T> Any for Twhere T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for Twhere T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for Twhere U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.