Documentation for Wein2D.js-WASM



wein2d
TextPositioning
Key
Sound
Sprite
VirtualCanvas



module wein2d

Holds all structs like sound and sprite as well as public functions, like drawing onto the canvas and getting mouse input.


fn rect_touching_rect(rect1PosX: f32, rect1PosY: f32, rect1SizeX: f32, rect1SizeY: f32, rect2PosX: f32, rect2PosY: f32, rect2SizeX: f32, rect2SizeY: f32) -> bool

Returns if a rectangle collides with a rectangle.

fn point_inside_rect(pointX: f32, pointY: f32, rectPosX: f32, rectPosY: f32, rectSizeX: f32, rectSizeY: f32) -> bool

Returns if a point is inside a rectangle.

fn rect_inside_rect(rect1PosX: f32, rect1PosY: f32, rect1SizeX: f32, rect1SizeY: f32, rect2PosX: f32, rect2PosY: f32, rect2SizeX: f32, rect2SizeY: f32) -> bool

Returns if a rectangle is insde of a rectangle.

fn get_width() -> f32

Returns the current width of the canvas.

fn get_height() -> f32

Returns the current height of the canvas.

fn get_delta_time() -> f32

Returns the time in seconds since the last frame call.

fn get_key(key: u32) -> bool

Returns if the specified key is pressed down. Use the Key-struct for specifying the key.

fn get_typed_text() -> String

Returns the last 1000 characters that have been after the page loaded.

fn set_typed_text(text: &str)

Sets the string that 'getTypedText()' returns.

fn get_mouse_x() -> f32

Returns the position of the mouse inside of the canvas on the x-axis.

fn get_mouse_y() -> f32

Returns the position of the mouse inside of the canvas on the y-axis.

fn get_mouse_l() -> bool

Returns if the left mouse button is currently pressed down.

fn get_mouse_s() -> bool

Returns if the scroll wheel is currently pressed down.

fn get_mouse_r() -> bool

Returns if the right mouse button is currently pressed down.

fn draw_rect(posX: f32, posY: f32, width: f32, height: f32, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Draws a rectangle onto the canvas.

fn draw_oval(posX: f32, posY: f32, width: f32, height: f32, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Draws an oval onto the canvas.

fn draw_sprite(sprite: &Sprite, posX: f32, posY: f32, colorA: u8)

fn draw_sprite_sized(sprite: &Sprite, posX: f32, posY: f32, width: f32, height: f32, colorA: u8)

fn draw_sprite_sized_source(sprite: &Sprite, posX: f32, posY: f32, width: f32, height: f32, srcPosX: u32, srcPosY: u32, srcWidth: u32, srcHeight: u32, colorA: u8)

Draws a Sprite onto the canvas.

fn draw_text(content: &str, posX: f32, posY: f32, fontSize: f32, fontFamily: &str, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

fn draw_text_positioned(content: &str, posX: f32, posY: f32, positioning: &str, fontSize: f32, fontFamily: &str, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Draws text onto the canvas. Use the TextPositioning-class for specifying the positioning.

fn fill(colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Completely fills the canvas.

fn draw_line(posX: f32, posY: f32, endX: f32, endY: f32, lineWidth: f32, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Draws a line onto the canvas.

fn draw_virtual_canvas(virtualCanvas: &VirtualCanvas, posX: f32, posY: f32, colorA: u8)

fn draw_virtual_canvas_sized(virtualCanvas: &VirtualCanvas, posX: f32, posY: f32, width: f32, height: f32, colorA: u8)

fn draw_virtual_canvas_sized_source(virtualCanvas: &VirtualCanvas, posX: f32, posY: f32, width: f32, height: f32, srcPosX: f32, srcPosY: f32, srcWidth: f32, srcHeight: f32, colorA: u8)

Draws a VirtualCanvas onto the canvas.



struct TextPositioning

Describes the orientation of rendered Text.


const LEFT: &'static str

Positions the text left of it's rendering coordinates.

const CENTER: &'static str

Positions the text centered around it's rendering coordinates.

const RIGHT: &'static str

Positions the text right of it's rendering coordinates.



struct Key

Describes a button on a keyboard.


const CTRL: u32

Corresponds to the 'ctrl'-key on a keyboard.

const SHIFT: u32

Corresponds to the 'shift'-key on a keyboard.

const SPACE: u32

Corresponds to the spacebar on a keyboard.

const BACKSPACE: u32

Corresponds to the backspace on a keyboard.

const ENTER: u32

Corresponds to the enter-key / return-key on a keyboard.

const A: u32

Corresponds to the 'a'-key on a keyboard.

const B: u32

Corresponds to the 'b'-key on a keyboard.

const C: u32

Corresponds to the 'c'-key on a keyboard.

const D: u32

Corresponds to the 'd'-key on a keyboard.

const E: u32

Corresponds to the 'e'-key on a keyboard.

const F: u32

Corresponds to the 'f'-key on a keyboard.

const G: u32

Corresponds to the 'g'-key on a keyboard.

const H: u32

Corresponds to the 'h'-key on a keyboard.

const I: u32

Corresponds to the 'i'-key on a keyboard.

const J: u32

Corresponds to the 'j'-key on a keyboard.

const K: u32

Corresponds to the 'k'-key on a keyboard.

const L: u32

Corresponds to the 'l'-key on a keyboard.

const M: u32

Corresponds to the 'm'-key on a keyboard.

const N: u32

Corresponds to the 'n'-key on a keyboard.

const O: u32

Corresponds to the 'o'-key on a keyboard.

const P: u32

Corresponds to the 'p'-key on a keyboard.

const Q: u32

Corresponds to the 'q'-key on a keyboard.

const R: u32

Corresponds to the 'r'-key on a keyboard.

const S: u32

Corresponds to the 's'-key on a keyboard.

const T: u32

Corresponds to the 't'-key on a keyboard.

const U: u32

Corresponds to the 'u'-key on a keyboard.

const V: u32

Corresponds to the 'v'-key on a keyboard.

const W: u32

Corresponds to the 'w'-key on a keyboard.

const X: u32

Corresponds to the 'x'-key on a keyboard.

const Y: u32

Corresponds to the 'y'-key on a keyboard.

const Z: u32

Corresponds to the 'z'-key on a keyboard.

const UP: u32

Corresponds to the arrow up on a keyboard.

const DOWN: u32

Corresponds to the arrow down on a keyboard.

const LEFT: u32

Corresponds to the arrow left on a keyboard.

const RIGHT: u32

Corresponds to the arrow right on a keyboard.

const N0: u32

Corresponds to the '0'-key on a keyboard.

const N1: u32

Corresponds to the '1'-key on a keyboard.

const N2: u32

Corresponds to the '2'-key on a keyboard.

const N3: u32

Corresponds to the '3'-key on a keyboard.

const N4: u32

Corresponds to the '4'-key on a keyboard.

const N5: u32

Corresponds to the '5'-key on a keyboard.

const N6: u32

Corresponds to the '6'-key on a keyboard.

const N7: u32

Corresponds to the '7'-key on a keyboard.

const N8: u32

Corresponds to the '8'-key on a keyboard.

const N9: u32

Corresponds to the '9'-key on a keyboard.

const F1: u32

Corresponds to the 'F1'-key on a keyboard.

const F2: u32

Corresponds to the 'F2'-key on a keyboard.

const F3: u32

Corresponds to the 'F3'-key on a keyboard.

const F4: u32

Corresponds to the 'F4'-key on a keyboard.

const F5: u32

Corresponds to the 'F5'-key on a keyboard.

const F6: u32

Corresponds to the 'F6'-key on a keyboard.

const F7: u32

Corresponds to the 'F7'-key on a keyboard.

const F8: u32

Corresponds to the 'F8'-key on a keyboard.

const F9: u32

Corresponds to the 'F9'-key on a keyboard.

const F10: u32

Corresponds to the 'F10'-key on a keyboard.

const F11: u32

Corresponds to the 'F11'-key on a keyboard.

const F12: u32

Corresponds to the 'F12'-key on a keyboard.

const ESC: u32

Corresponds to the escape-key on a keyboard.



struct Sound

Struct for storing sound files and playing them.


fn new(filePath: &str) -> Sound

Creates a Sound from the specified file.

fn set_volume(&self, volume: f32)

Sets the Sound's volume. Also applies to sound already in playback. 'volume' should be a value between 0 and 1.

fn play(&self)

Plays the sound. Starts from the beginning if already playing.

fn set_looping(&self, looping: bool)

Specifies if the sound should be looped infinitely.

fn stop(&self)

Stops playback of the sound.

fn is_playing(&self) -> bool

Returns if the sound is currently played back.



struct Sprite

Class for storing image files.


fn new(filePath: &str) -> Sprite

Creates a Sprite from the specified file.

fn get_width(&self) -> u32

Returns the Sprite's width.

fn get_height(&self) -> u32

Returns the Sprite's height.



struct VirtualCanvas

A virtual surface to draw onto. Can be drawn onto the main canvas afterwards.


fn new(width: u32, height: u32) -> VirtualCanvas

Creates a new VirtualCanvas with the specified dimensions.

fn get_width(&self) -> u32

Returns the width of the VirtualCanvas.

fn get_height(&self) -> u32

Returns the height of the VirtualCanvas.

fn draw_rect(&self, posX: f32, posY: f32, width: f32, height: f32, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Draws a rectangle onto the VirtualCanvas.

fn draw_oval(&self, posX: f32, posY: f32, width: f32, height: f32, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Draws an oval onto the VirtualCanvas.

fn draw_sprite(&self, sprite: &Sprite, posX: f32, posY: f32, colorA: u8)

fn draw_sprite_sized(&self, sprite: &Sprite, posX: f32, posY: f32, width: f32, height: f32, colorA: u8)

fn draw_sprite_sized_source(&self, sprite: &Sprite, posX: f32, posY: f32, width: f32, height: f32, srcPosX: u32, srcPosY: u32, srcWidth: u32, srcHeight: u32, colorA: u8)

Draws a Sprite onto the VirtualCanvas.

fn draw_text(&self, content: &str, posX: f32, posY: f32, fontSize: f32, fontFamily: &str, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

fn draw_text_positioned(&self, content: &str, posX: f32, posY: f32, positioning: &str, fontSize: f32, fontFamily: &str, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Draws text onto the VirtualCanvas. Use the TextPositioning-class for specifying the positioning.

fn fill(&self, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Completely fills the VirtualCanvas.

fn draw_line(&self, posX: f32, posY: f32, endX: f32, endY: f32, lineWidth: f32, colorA: u8, colorR: u8, colorG: u8, colorB: u8)

Draws a line onto the VirtualCanvas.

fn draw_virtual_canvas(&self, virtualCanvas: &VirtualCanvas, posX: f32, posY: f32, colorA: u8)

fn draw_virtual_canvas_sized(&self, virtualCanvas: &VirtualCanvas, posX: f32, posY: f32, width: f32, height: f32, colorA: u8)

fn draw_virtual_canvas_sized_source(&self, virtualCanvas: &VirtualCanvas, posX: f32, posY: f32, width: f32, height: f32, srcPosX: f32, srcPosY: f32, srcWidth: f32, srcHeight: f32, colorA: u8)

Draws a VirtualCanvas onto the VirtualCanvas.



© Copyright 2022 DevTaube