bn::palette_bitmap_bg_ptr class

std::shared_ptr like smart pointer that retains shared ownership of a palette bitmap background.

Several palette_bitmap_bg_ptr objects may own the same background.

The background is released when the last remaining palette_bitmap_bg_ptr owning it is destroyed.

Public static functions

static auto dimensions() -> size
Returns the size in pixels of the backgrounds.
static auto create(const bg_palette_item& palette_item) -> palette_bitmap_bg_ptr
Creates a palette_bitmap_bg_ptr from the given bg_palette_item.
static auto create(const bg_palette_ptr& palette) -> palette_bitmap_bg_ptr
Creates a palette_bitmap_bg_ptr from the given bg_palette_ptr.
static auto create(bg_palette_ptr&& palette) -> palette_bitmap_bg_ptr
Creates a palette_bitmap_bg_ptr from a moved bg_palette_ptr.
static auto create(const palette_bitmap_bg_builder& builder) -> palette_bitmap_bg_ptr
Creates a palette_bitmap_bg_ptr from a palette_bitmap_bg_builder reference.
static auto create(palette_bitmap_bg_builder&& builder) -> palette_bitmap_bg_ptr
Creates a palette_bitmap_bg_ptr from a moved palette_bitmap_bg_builder.
static auto create_optional(const bg_palette_item& palette_item) -> optional<palette_bitmap_bg_ptr>
Creates a palette_bitmap_bg_ptr from the given bg_palette_item.
static auto create_optional(const bg_palette_ptr& palette) -> optional<palette_bitmap_bg_ptr>
Creates a palette_bitmap_bg_ptr from the given bg_palette_ptr.
static auto create_optional(bg_palette_ptr&& palette) -> optional<palette_bitmap_bg_ptr>
Creates a palette_bitmap_bg_ptr from a moved bg_palette_ptr.
static auto create_optional(const palette_bitmap_bg_builder& builder) -> optional<palette_bitmap_bg_ptr>
Creates a palette_bitmap_bg_ptr from a palette_bitmap_bg_builder reference.
static auto create_optional(palette_bitmap_bg_builder&& builder) -> optional<palette_bitmap_bg_ptr>
Creates a palette_bitmap_bg_ptr from a moved palette_bitmap_bg_builder.

Constructors, destructors, conversion operators

palette_bitmap_bg_ptr(const palette_bitmap_bg_ptr& other)
Copy constructor.
palette_bitmap_bg_ptr(palette_bitmap_bg_ptr&& other) noexcept
Move constructor.
~palette_bitmap_bg_ptr()
Releases the referenced background if no more palette_bitmap_bg_ptr objects reference to it.

Public functions

auto operator=(const palette_bitmap_bg_ptr& other) -> palette_bitmap_bg_ptr&
Copy assignment operator.
auto operator=(palette_bitmap_bg_ptr&& other) -> palette_bitmap_bg_ptr& noexcept
Move assignment operator.
auto page() const -> span<const uint16_t>
Returns a span of the hidden frame buffer.
auto page() -> span<uint16_t>
Returns a span of the hidden frame buffer.
void flip_page_later()
Swaps the hidden frame buffer in the next core::update call.
void flip_page_now()
Swaps the hidden frame buffer without waiting to the next core::update call.
auto palette() const -> const bg_palette_ptr&
Returns the color palette used by this background.
void set_palette(const bg_palette_ptr& palette)
Sets the color palette to use by this background.
void set_palette(bg_palette_ptr&& palette)
Sets the color palette to use by this background.
void set_palette(const bg_palette_item& palette_item)
Replaces the color palette used by this background with a new one created with the given bg_palette_item.
auto x() const -> fixed
Returns the horizontal position of the background (relative to its camera, if it has one).
void set_x(fixed x)
Sets the horizontal position of the background (relative to its camera, if it has one).
auto y() const -> fixed
Returns the vertical position of the background (relative to its camera, if it has one).
void set_y(fixed y)
Sets the vertical position of the background (relative to its camera, if it has one).
auto position() const -> const fixed_point&
Returns the position of the background (relative to its camera, if it has one).
void set_position(fixed x, fixed y)
Sets the position of the background (relative to its camera, if it has one).
void set_position(const fixed_point& position)
Sets the position of the background (relative to its camera, if it has one).
auto top_left_x() const -> fixed
Returns the horizontal top-left position of the background (relative to its camera, if it has one).
void set_top_left_x(fixed top_left_x)
Sets the horizontal top-left position of the background (relative to its camera, if it has one).
auto top_left_y() const -> fixed
Returns the vertical top-left position of the background (relative to its camera, if it has one).
void set_top_left_y(fixed top_left_y)
Sets the vertical top-left position of the background (relative to its camera, if it has one).
auto top_left_position() const -> fixed_point
Returns the top-left position of the background (relative to its camera, if it has one).
void set_top_left_position(fixed top_left_x, fixed top_left_y)
Sets the top-left position of the background (relative to its camera, if it has one).
void set_top_left_position(const fixed_point& top_left_position)
Sets the top-left position of the background (relative to its camera, if it has one).
auto rotation_angle() const -> fixed
Returns the rotation angle in degrees of the background.
void set_rotation_angle(fixed rotation_angle)
Sets the rotation angle in degrees of the background.
void set_rotation_angle_safe(fixed rotation_angle)
Sets the rotation angle in degrees of the background.
auto horizontal_scale() const -> fixed
Returns the horizontal scale of the background.
void set_horizontal_scale(fixed horizontal_scale)
Sets the horizontal scale of the background.
auto vertical_scale() const -> fixed
Returns the vertical scale of the background.
void set_vertical_scale(fixed vertical_scale)
Sets the vertical scale of the background.
void set_scale(fixed scale)
Sets the scale of the background.
void set_scale(fixed horizontal_scale, fixed vertical_scale)
Sets the scale of the background.
auto horizontal_shear() const -> fixed
Returns the horizontal shear of the background.
void set_horizontal_shear(fixed horizontal_shear)
Sets the horizontal shear of the background.
auto vertical_shear() const -> fixed
Returns the vertical shear of the background.
void set_vertical_shear(fixed vertical_shear)
Sets the vertical shear of the background.
void set_shear(fixed shear)
Sets the shear of the background.
void set_shear(fixed horizontal_shear, fixed vertical_shear)
Sets the shear of the background.
auto horizontal_flip() const -> bool
Indicates if this background is flipped in the horizontal axis or not.
void set_horizontal_flip(bool horizontal_flip)
Sets if this background must be flipped in the horizontal axis or not.
auto vertical_flip() const -> bool
Indicates if this background must be flipped in the vertical axis or not.
void set_vertical_flip(bool vertical_flip)
Sets if this background must be flipped in the vertical axis or not.
auto pivot_x() const -> fixed
Returns the horizontal position of the affine transformations pivot point of this background.
void set_pivot_x(fixed pivot_x)
Sets the horizontal position of the affine transformations pivot point of this background.
auto pivot_y() const -> fixed
Returns the vertical position of the affine transformations pivot point of this background.
void set_pivot_y(fixed pivot_y)
Sets the vertical position of the affine transformations pivot point of this background.
auto pivot_position() const -> const fixed_point&
Returns the position of the affine transformations pivot point of this background.
void set_pivot_position(fixed pivot_x, fixed pivot_y)
Sets the position of the affine transformations pivot point of this background.
void set_pivot_position(const fixed_point& pivot_position)
Sets the position of the affine transformations pivot point of this background.
auto mat_attributes() const -> const affine_bg_mat_attributes&
Returns the attributes of the position and the transformation matrix of this background.
void set_mat_attributes(const affine_mat_attributes& mat_attributes)
Sets the attributes of the affine transformation matrix of this background.
auto priority() const -> int
Returns the priority of the background relative to sprites and other backgrounds.
void set_priority(int priority)
Sets the priority of the background relative to sprites and other backgrounds.
auto mosaic_enabled() const -> bool
Indicates if the mosaic effect must be applied to this background or not.
void set_mosaic_enabled(bool mosaic_enabled)
Sets if the mosaic effect must be applied to this background or not.
auto blending_enabled() const -> bool
Indicates if blending must be applied to this background or not.
void set_blending_enabled(bool blending_enabled)
Sets if blending must be applied to this background or not.
auto blending_top_enabled() const -> bool
Indicates if this background is part of the blending top layer or not.
void set_blending_top_enabled(bool blending_top_enabled)
Sets if this background is part of the blending top layer or not.
auto blending_bottom_enabled() const -> bool
Indicates if this background is part of the blending bottom layer or not.
void set_blending_bottom_enabled(bool blending_bottom_enabled)
Sets if this background is part of the blending bottom layer or not.
auto green_swap_mode() const -> bn::green_swap_mode
Indicates how this background must be displayed when green swap is enabled.
void set_green_swap_mode(bn::green_swap_mode green_swap_mode)
Sets how this background must be displayed when green swap is enabled.
auto visible() const -> bool
Indicates if this background must be committed to the GBA or not.
void set_visible(bool visible)
Sets if this background must be committed to the GBA or not.
auto visible_in_window(const window& window) const -> bool
Indicates if this background is visible in the given window or not.
void set_visible_in_window(bool visible, window& window)
Sets if this background must be visible in the given window or not.
auto camera() const -> const optional<camera_ptr>&
Returns the camera_ptr attached to this background (if any).
void set_camera(const camera_ptr& camera)
Sets the camera_ptr attached to this background.
void set_camera(camera_ptr&& camera)
Sets the camera_ptr attached to this background.
void set_camera(const optional<camera_ptr>& camera)
Sets or removes the camera_ptr attached to this background.
void set_camera(optional<camera_ptr>&& camera)
Sets or removes the camera_ptr attached to this background.
void remove_camera()
Removes the camera_ptr attached to this background (if any).
auto attributes() const -> bitmap_bg_attributes
Returns the attributes to commit to the GBA for this background.
void set_attributes(const bitmap_bg_attributes& attributes)
Sets the attributes to commit to the GBA for this background.
auto hw_id() const -> optional<int>
Returns the hardware ID assigned to this background or bn::nullopt if no hardware ID has been assigned.
auto handle() const -> const void*
Returns the internal handle.
void swap(palette_bitmap_bg_ptr& other)
Exchanges the contents of this palette_bitmap_bg_ptr with those of the other one.

Friends

void swap(palette_bitmap_bg_ptr& a, palette_bitmap_bg_ptr& b)
Exchanges the contents of an palette_bitmap_bg_ptr with those of another one.
auto operator==(const palette_bitmap_bg_ptr& a, const palette_bitmap_bg_ptr& b) -> bool defaulted
Default equal operator.

Function documentation

static palette_bitmap_bg_ptr bn::palette_bitmap_bg_ptr::create(const bg_palette_item& palette_item)

Creates a palette_bitmap_bg_ptr from the given bg_palette_item.

Parameters
palette_item bg_palette_item containing the required information to generate the palette used by the background.
Returns The requested palette_bitmap_bg_ptr.

static palette_bitmap_bg_ptr bn::palette_bitmap_bg_ptr::create(const bg_palette_ptr& palette)

Creates a palette_bitmap_bg_ptr from the given bg_palette_ptr.

Parameters
palette bg_palette_ptr reference.
Returns The requested palette_bitmap_bg_ptr.

static palette_bitmap_bg_ptr bn::palette_bitmap_bg_ptr::create(bg_palette_ptr&& palette)

Creates a palette_bitmap_bg_ptr from a moved bg_palette_ptr.

Parameters
palette bg_palette_ptr to move.
Returns The requested palette_bitmap_bg_ptr.

static palette_bitmap_bg_ptr bn::palette_bitmap_bg_ptr::create(const palette_bitmap_bg_builder& builder)

Creates a palette_bitmap_bg_ptr from a palette_bitmap_bg_builder reference.

Parameters
builder palette_bitmap_bg_builder reference.
Returns The requested palette_bitmap_bg_ptr.

static palette_bitmap_bg_ptr bn::palette_bitmap_bg_ptr::create(palette_bitmap_bg_builder&& builder)

Creates a palette_bitmap_bg_ptr from a moved palette_bitmap_bg_builder.

Parameters
builder palette_bitmap_bg_builder to move.
Returns The requested palette_bitmap_bg_ptr.

static optional<palette_bitmap_bg_ptr> bn::palette_bitmap_bg_ptr::create_optional(const bg_palette_item& palette_item)

Creates a palette_bitmap_bg_ptr from the given bg_palette_item.

Parameters
palette_item bg_palette_item containing the required information to generate the palette used by the background.
Returns The requested palette_bitmap_bg_ptr if it could be allocated; bn::nullopt otherwise.

static optional<palette_bitmap_bg_ptr> bn::palette_bitmap_bg_ptr::create_optional(const bg_palette_ptr& palette)

Creates a palette_bitmap_bg_ptr from the given bg_palette_ptr.

Parameters
palette bg_palette_ptr reference.
Returns The requested palette_bitmap_bg_ptr if it could be allocated; bn::nullopt otherwise.

static optional<palette_bitmap_bg_ptr> bn::palette_bitmap_bg_ptr::create_optional(bg_palette_ptr&& palette)

Creates a palette_bitmap_bg_ptr from a moved bg_palette_ptr.

Parameters
palette bg_palette_ptr to move.
Returns The requested palette_bitmap_bg_ptr if it could be allocated; bn::nullopt otherwise.

static optional<palette_bitmap_bg_ptr> bn::palette_bitmap_bg_ptr::create_optional(const palette_bitmap_bg_builder& builder)

Creates a palette_bitmap_bg_ptr from a palette_bitmap_bg_builder reference.

Parameters
builder palette_bitmap_bg_builder reference.
Returns The requested palette_bitmap_bg_ptr if it could be allocated; bn::nullopt otherwise.

static optional<palette_bitmap_bg_ptr> bn::palette_bitmap_bg_ptr::create_optional(palette_bitmap_bg_builder&& builder)

Creates a palette_bitmap_bg_ptr from a moved palette_bitmap_bg_builder.

Parameters
builder palette_bitmap_bg_builder to move.
Returns The requested palette_bitmap_bg_ptr if it could be allocated; bn::nullopt otherwise.

bn::palette_bitmap_bg_ptr::palette_bitmap_bg_ptr(const palette_bitmap_bg_ptr& other)

Copy constructor.

Parameters
other palette_bitmap_bg_ptr to copy.

bn::palette_bitmap_bg_ptr::palette_bitmap_bg_ptr(palette_bitmap_bg_ptr&& other) noexcept

Move constructor.

Parameters
other palette_bitmap_bg_ptr to move.

palette_bitmap_bg_ptr& bn::palette_bitmap_bg_ptr::operator=(const palette_bitmap_bg_ptr& other)

Copy assignment operator.

Parameters
other palette_bitmap_bg_ptr to copy.
Returns Reference to this.

palette_bitmap_bg_ptr& bn::palette_bitmap_bg_ptr::operator=(palette_bitmap_bg_ptr&& other) noexcept

Move assignment operator.

Parameters
other palette_bitmap_bg_ptr to move.
Returns Reference to this.

void bn::palette_bitmap_bg_ptr::flip_page_now()

Swaps the hidden frame buffer without waiting to the next core::update call.

Expect lack of vsync issues like screen tearing.

void bn::palette_bitmap_bg_ptr::set_palette(const bg_palette_ptr& palette)

Sets the color palette to use by this background.

Parameters
palette bg_palette_ptr to copy.

void bn::palette_bitmap_bg_ptr::set_palette(bg_palette_ptr&& palette)

Sets the color palette to use by this background.

Parameters
palette bg_palette_ptr to move.

void bn::palette_bitmap_bg_ptr::set_palette(const bg_palette_item& palette_item)

Replaces the color palette used by this background with a new one created with the given bg_palette_item.

Parameters
palette_item It creates the color palette to use by this background.

Before creating a new color palette, the bg_palette_ptr used by this background is removed, so VRAM usage is reduced.

void bn::palette_bitmap_bg_ptr::set_position(fixed x, fixed y)

Sets the position of the background (relative to its camera, if it has one).

Parameters
x Horizontal position of the background (relative to its camera, if it has one).
y Vertical position of the background (relative to its camera, if it has one).

void bn::palette_bitmap_bg_ptr::set_top_left_position(fixed top_left_x, fixed top_left_y)

Sets the top-left position of the background (relative to its camera, if it has one).

Parameters
top_left_x Horizontal top-left position of the background (relative to its camera, if it has one).
top_left_y Vertical top-left position of the background (relative to its camera, if it has one).

void bn::palette_bitmap_bg_ptr::set_rotation_angle(fixed rotation_angle)

Sets the rotation angle in degrees of the background.

Parameters
rotation_angle Rotation angle in degrees, in the range [0..360].

void bn::palette_bitmap_bg_ptr::set_rotation_angle_safe(fixed rotation_angle)

Sets the rotation angle in degrees of the background.

Parameters
rotation_angle Rotation angle in degrees, in any range.

void bn::palette_bitmap_bg_ptr::set_scale(fixed horizontal_scale, fixed vertical_scale)

Sets the scale of the background.

Parameters
horizontal_scale Horizontal scale.
vertical_scale Vertical scale.

void bn::palette_bitmap_bg_ptr::set_shear(fixed horizontal_shear, fixed vertical_shear)

Sets the shear of the background.

Parameters
horizontal_shear Horizontal shear.
vertical_shear Vertical shear.

void bn::palette_bitmap_bg_ptr::set_pivot_position(fixed pivot_x, fixed pivot_y)

Sets the position of the affine transformations pivot point of this background.

Parameters
pivot_x Horizontal position of the pivot point.
pivot_y Vertical position of the pivot point.

void bn::palette_bitmap_bg_ptr::set_pivot_position(const fixed_point& pivot_position)

Sets the position of the affine transformations pivot point of this background.

Parameters
pivot_position Position of the pivot point.

int bn::palette_bitmap_bg_ptr::priority() const

Returns the priority of the background relative to sprites and other backgrounds.

Backgrounds with higher priority are drawn first (and therefore can be covered by later sprites and backgrounds).

void bn::palette_bitmap_bg_ptr::set_priority(int priority)

Sets the priority of the background relative to sprites and other backgrounds.

Parameters
priority Priority in the range [0..3].

Backgrounds with higher priority are drawn first (and therefore can be covered by later sprites and backgrounds).

bool bn::palette_bitmap_bg_ptr::blending_enabled() const

Indicates if blending must be applied to this background or not.

Blending is applied to this background by making it part of the blending top layer.

void bn::palette_bitmap_bg_ptr::set_blending_enabled(bool blending_enabled)

Sets if blending must be applied to this background or not.

Blending is applied to this background by making it part of the blending top layer.

void bn::palette_bitmap_bg_ptr::set_camera(const camera_ptr& camera)

Sets the camera_ptr attached to this background.

Parameters
camera camera_ptr to copy to this background.

void bn::palette_bitmap_bg_ptr::set_camera(camera_ptr&& camera)

Sets the camera_ptr attached to this background.

Parameters
camera camera_ptr to move to this background.

void bn::palette_bitmap_bg_ptr::set_camera(const optional<camera_ptr>& camera)

Sets or removes the camera_ptr attached to this background.

Parameters
camera Optional camera_ptr to copy to this background.

void bn::palette_bitmap_bg_ptr::set_camera(optional<camera_ptr>&& camera)

Sets or removes the camera_ptr attached to this background.

Parameters
camera Optional camera_ptr to move to this background.

optional<int> bn::palette_bitmap_bg_ptr::hw_id() const

Returns the hardware ID assigned to this background or bn::nullopt if no hardware ID has been assigned.

Normally you should not need to call this function, but it can be useful for messing with HDMA for example.

A background doesn't have an assigned hardware ID if it is not visible.

Assigned hardware ID can change after calling this method if some properties of this background or others are updated.

Call this method at your own risk.

void bn::palette_bitmap_bg_ptr::swap(palette_bitmap_bg_ptr& other)

Exchanges the contents of this palette_bitmap_bg_ptr with those of the other one.

Parameters
other palette_bitmap_bg_ptr to exchange the contents with.

void swap(palette_bitmap_bg_ptr& a, palette_bitmap_bg_ptr& b)

Exchanges the contents of an palette_bitmap_bg_ptr with those of another one.

Parameters
a First palette_bitmap_bg_ptr to exchange the contents with.
b Second palette_bitmap_bg_ptr to exchange the contents with.