qwac-sys 0.28.1

The FFI crates for QWAC
Documentation
#[derive(Clone, Copy, Hash, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[repr(u8)]
pub enum CompositeOperation {
    /// This is the default setting and draws new shapes on top of the existing canvas content.
    SourceOver = 0,

    /// The new shape is drawn only where both the new shape and the destination canvas overlap.
    /// Everything else is made transparent.
    SourceIn,

    /// The new shape is drawn where it doesn't overlap the existing canvas content.
    SourceOut,

    /// The new shape is only drawn where it overlaps the existing canvas content.
    SourceAtop,

    /// New shapes are drawn behind the existing canvas content.
    DestinationOver,

    /// The existing canvas content is kept where both the new shape and existing canvas content
    /// overlap. Everything else is made transparent.
    DestinationIn,

    /// The existing content is kept where it doesn't overlap the new shape.
    DestinationOut,

    /// The existing canvas is only kept where it overlaps the new shape. The new shape is drawn
    /// behind the canvas content.
    DestinationAtop,

    /// Where both shapes overlap the color is determined by adding color values.
    Lighter,

    /// Only the new shape is shown.
    Copy,

    /// Shapes are made transparent where both overlap and drawn normal everywhere else.
    Xor,

    /// The pixels of the top layer are multiplied with the corresponding pixel of the bottom
    /// layer. A darker picture is the result.
    Multiply,

    /// The pixels are inverted, multiplied, and inverted again. A lighter picture is the result
    /// (opposite of multiply)
    Screen,

    /// A combination of multiply and screen. Dark parts on the base layer become darker, and light
    /// parts become lighter.
    Overlay,

    /// Retains the darkest pixels of both layers.
    Darken,

    /// Retains the lightest pixels of both layers.
    Lighten,

    /// Divides the bottom layer by the inverted top layer.
    ColorDodge,

    /// Divides the inverted bottom layer by the top layer, and then inverts the result.
    ColorBurn,

    /// A combination of multiply and screen like overlay, but with top and bottom layer swapped.
    HardLight,

    /// A softer version of hardLight. Pure black or white does not result in pure black or white.
    SoftLight,

    /// Subtracts the bottom layer from the top layer or the other way round to always get a
    /// positive value.
    Difference,

    /// Like difference, but with lower contrast.
    Exclusion,

    /// Preserves the luma and chroma of the bottom layer, while adopting the hue of the top layer.
    Hue,

    /// Preserves the luma and hue of the bottom layer, while adopting the chroma of the top layer.
    Saturation,

    /// Preserves the luma of the bottom layer, while adopting the hue and chroma of the top layer.
    Color,

    /// Preserves the hue and chroma of the bottom layer, while adopting the luma of the top layer.
    Luminosity,
}

/// Textures are initialized asynchronously, so we have to set them via a
/// callback.
/// The callback is given a negative texture code on error.  On a negative
/// texture, the error code is the bit-flipped number, which is `-1 - texture`.
pub type TextureCallback = extern "C" fn(texture: i32, user_data: *mut ());

#[link(wasm_import_module = "qwac_graphics")]
extern "C" {
    pub fn canvas_create() -> i32;
    pub fn canvas_resize(canvas: i32, width_px: i32, height_px: i32);
    pub fn canvas_clear(canvas: i32);
    pub fn canvas_save(canvas: i32);
    pub fn canvas_restore(canvas: i32);
    pub fn canvas_set_global_alpha(canvas: i32, alpha: f32);
    pub fn canvas_set_global_composite_operation(canvas: i32, operation: CompositeOperation);
    pub fn canvas_set_fill_style(canvas: i32, style: *const u8, length: i32);
    pub fn canvas_set_stroke_style(canvas: i32, style: *const u8, length: i32);
    pub fn canvas_set_font(canvas: i32, font: *const u8, length: i32);
    pub fn canvas_set_line_width(canvas: i32, width: f32);
    pub fn canvas_path_begin(canvas: i32);
    pub fn canvas_path_close(canvas: i32);
    pub fn canvas_path_stroke(canvas: i32);
    pub fn canvas_path_fill(canvas: i32);
    pub fn canvas_path_move_to(canvas: i32, x: f32, y: f32);
    pub fn canvas_path_line_to(canvas: i32, x: f32, y: f32);
    pub fn canvas_path_rectangle(canvas: i32, x: f32, y: f32, width: f32, height: f32);
    pub fn canvas_path_ellipse(
        canvas: i32,
        x: f32,
        y: f32,
        radius_x: f32,
        radius_y: f32,
        rotation: f32,
        start_angle: f32,
        end_angle: f32,
        counter_clockwise: i32,
    );
    pub fn canvas_path_arc(
        canvas: i32,
        x: f32,
        y: f32,
        radius: f32,
        start_angle: f32,
        end_angle: f32,
        counter_clockwise: i32,
    );
    pub fn canvas_path_arc_to(canvas: i32, x1: f32, y1: f32, x2: f32, y2: f32, radius: f32);
    pub fn canvas_fill_text(
        canvas: i32,
        text: *const u8,
        length: i32,
        x: f32,
        y: f32,
        max_width: f32,
    );
    pub fn canvas_stroke_text(
        canvas: i32,
        text: *const u8,
        length: i32,
        x: f32,
        y: f32,
        max_width: f32,
    );
    pub fn canvas_fill_rectangle(canvas: i32, x: f32, y: f32, width: f32, height: f32);
    pub fn canvas_stroke_rectangle(canvas: i32, x: f32, y: f32, width: f32, height: f32);
    pub fn canvas_clear_rectangle(canvas: i32, x: f32, y: f32, width: f32, height: f32);

    pub fn canvas_draw_texture(
        canvas: i32,
        texture: i32,
        source_x: f32,
        source_y: f32,
        source_width: f32,
        source_height: f32,
        dest_x: f32,
        dest_y: f32,
        dest_width: f32,
        dest_height: f32,
    );

    pub fn canvas_draw_canvas(
        canvas: i32,
        source_canvas: i32,
        source_x: f32,
        source_y: f32,
        source_width: f32,
        source_height: f32,
        dest_x: f32,
        dest_y: f32,
        dest_width: f32,
        dest_height: f32,
    );

    pub fn canvas_width(canvas: i32) -> i32;
    pub fn canvas_height(canvas: i32) -> i32;
    pub fn canvas_drop(canvas: i32);

    pub fn texture_from_canvas(canvas: i32, callback: TextureCallback, user_data: *mut ());
    pub fn texture_from_texture(texture: i32, callback: TextureCallback, user_data: *mut ());
    pub fn texture_from_rgba(
        data: *const u8,
        width: i32,
        height: i32,
        callback: TextureCallback,
        user_data: *mut (),
    );
    pub fn texture_from_file(
        data: *const u8,
        size: i32,
        mime_type: *const u8,
        mime_type_size: i32,
        callback: TextureCallback,
        user_data: *mut (),
    );
    pub fn texture_width(texture: i32) -> i32;
    pub fn texture_height(texture: i32) -> i32;
    pub fn texture_drop(texture: i32);
}