Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions example/audio/main.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,5 @@ fn main {
pub fn boot() -> Unit {
@audio.out.add_file(b"pickupCoin") |> ignore
let gain = @audio.out.add_gain(0.5)
gain.add_sine(@audio.A4, 1) |> ignore
}

///|
/// update is called ~60 times per second.
pub fn update() -> Unit {

}

///|
/// render is called before updating the image on the screen.
///
/// It might be called less often than `update` if the device sees that the game
/// is slow and needs more resources.
/// This is the best place to call all drawing functions.
pub fn render() -> Unit {

gain.add_sine(@audio.A4, 0) |> ignore
}
50 changes: 50 additions & 0 deletions src/graphics.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,56 @@ pub fn draw_sub_image(sub_image : SubImage, point : Point) -> Unit {
sub_image.image |> @memory.keep
}

///|
/// Tile the given screen area with the provided sub-image.
pub fn draw_sub_tile(sub_image : SubImage, point : Point, size : Size) -> Unit {
@ffi.draw_sub_tile(
@memory.fixedbytes_addr(sub_image.image.0),
@memory.fixedbytes_size(sub_image.image.0),
point.x,
point.y,
size.w,
size.h,
sub_image.point_x,
sub_image.point_y,
sub_image.size_w,
sub_image.size_h,
)
sub_image.image |> @memory.keep
}

///|
/// Fill the given area with the given 9-slice.
///
/// A 9-slice is used to tile an area with 9 sub-images: 4 corners,
/// 4 edges, and 1 middle segment. It is useful for speech bubbles
/// and other stylish boxes.
///
/// The whole image is the 9-slice. The sub-image is the center area of the 9-slice.
///
/// If the target area is bigger than the 9-slice segments,
/// all the segments (except corners) are repeated ("tiled")
/// without stretching or mirroring.
pub fn draw_nine_slice(
sub_image : SubImage,
point : Point,
size : Size,
) -> Unit {
@ffi.draw_nine_slice(
@memory.fixedbytes_addr(sub_image.image.0),
@memory.fixedbytes_size(sub_image.image.0),
point.x,
point.y,
size.w,
size.h,
sub_image.point_x,
sub_image.point_y,
sub_image.size_w,
sub_image.size_h,
)
sub_image.image |> @memory.keep
}

///|
/// Reference to the current image. Kept to make sure the image doesn't
/// get garbage collected.
Expand Down
28 changes: 28 additions & 0 deletions src/internal/ffi/graphics.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,34 @@ pub fn draw_sub_image(
sub_height : Int,
) = "graphics" "draw_sub_image"

///|
pub fn draw_sub_tile(
image_ptr : UInt,
image_len : Int,
x : Int,
y : Int,
w : Int,
h : Int,
sub_x : Int,
sub_y : Int,
sub_width : Int,
sub_height : Int,
) = "graphics" "draw_sub_tile"

///|
pub fn draw_nine_slice(
image_ptr : UInt,
image_len : Int,
x : Int,
y : Int,
w : Int,
h : Int,
sub_x : Int,
sub_y : Int,
sub_width : Int,
sub_height : Int,
) = "graphics" "draw_nine_slice"

///|
/// Set the target image for all subsequent drawing operations.
///
Expand Down
Loading