diff --git a/example/audio/main.mbt b/example/audio/main.mbt index 4f083cc..97f86e7 100644 --- a/example/audio/main.mbt +++ b/example/audio/main.mbt @@ -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 } diff --git a/src/graphics.mbt b/src/graphics.mbt index 1d27ca5..51ce578 100644 --- a/src/graphics.mbt +++ b/src/graphics.mbt @@ -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. diff --git a/src/internal/ffi/graphics.mbt b/src/internal/ffi/graphics.mbt index 01e1fd7..af4f73f 100644 --- a/src/internal/ffi/graphics.mbt +++ b/src/internal/ffi/graphics.mbt @@ -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. ///