canvas interface - Outerra/anteworld GitHub Wiki
Canvas interface is used to draw lines, texts, images etc. on screen.
this.canvas = this.$query_interface("ot::js::canvas.create", true, true);
self.canvas = query_interface("lua.ot.canvas.create", true, true)
void destroy(); |
||
Parameter Description | Returns | Description |
---|---|---|
Destroy the canvas | ||
float2 get_size() const; |
||
Parameter Description | Returns | Description |
return: float2 | Get the size | |
void set_size(const float2& new_size); |
||
Parameter Description | Returns | Description |
new_size: new size | Set the size | |
void load_identity(); |
||
Parameter Description | Returns | Description |
Set all transformations to identity | ||
void translate(float x, float y); |
||
Parameter Description | Returns | Description |
x: translation on the x-axis y: translation on the y-axis |
Apply 2D translation | |
void rotate(float angle); |
||
Parameter Description | Returns | Description |
angle: rotation angle in radians (CW) | Apply rotation transformation | |
void scale(float x, float y); |
||
Parameter Description | Returns | Description |
x: scale factor on the x-axis y: scale factor on the y-axis |
Apply scale transformation | |
void set_line_params(float width, float smooth_size); |
||
Parameter Description | Returns | Description |
width: line width smooth_size: line smooth size |
Set line parameters | |
void push_state(); |
||
Parameter Description | Returns | Description |
Push current state to stack | ||
void pop_state(); |
||
Parameter Description | Returns | Description |
Pop state from stack | ||
void fill_rect(float x, float y, float w, float h, ot::color color); |
||
Parameter Description | Returns | Description |
x: x position y: y position w: width h: height color: rectangle color |
Draw filled rectangle | |
uint load_font(const coid::token& path); |
||
Parameter Description | Returns | Description |
path: font file path | return: uint | Load a font and return its handle |
uint load_image(const coid::token& path); |
||
Parameter Description | Returns | Description |
path: image file path | return: uint | Load an image and return its handle |
void draw_text(uint font, float x, float y, const coid::token& text, ot::color color); |
||
Parameter Description | Returns | Description |
font: font handle x: x position y: y position text: text to draw color: text color |
Draw text | |
void draw_text_wh(uint font, float x, float y, float w, float h, ot::anchor anchor, const coid::token& text, ot::color color, ot::color background_color); |
||
Parameter Description | Returns | Description |
---|---|---|
font: font handle x: x position y: y position w: width h: height anchor: anchor flags text: text to draw color: text color background_color: background color |
Draw text with anchor flags | |
void draw_text_ft(const coid::token& font, uint pixel_height, float x, float y, const coid::token& text, ot::color color); |
||
Parameter Description | Returns | Description |
---|---|---|
font: font handle pixel_height: font size in pixels x: x position y: y position text: text to draw color: text color |
Draw text with specified font size | |
void draw_image(uint image_id, float x, float y, ot::color color); |
||
Parameter Description | Returns | Description |
---|---|---|
image_id: image handle x: x position y: y position color: image color |
Draw an image | |
void draw_image_wh(uint image_id, float x, float y, float w, float h, ot::color color); |
||
Parameter Description | Returns | Description |
image_id: image handle x: x position y: y position w: width h: height color: image color |
Draw an image with specified width and height | |
void draw_image2(uint image_id, float x, float y, ot::color color); |
||
Parameter Description | Returns | Description |
image_id: image handle x: x position y: y position color: image color |
Draw an image (variant 2) | |
void draw_image2_scale(uint image_id, float x, float y, float w, float h, ot::color color); |
||
Parameter Description | Returns | Description |
image_id: image handle x: x position y: y position w: width h: height color: image color |
Draw a scaled image (variant 2) | |
void draw_line(float x, float y, float x2, float y2, ot::color color); |
||
Parameter Description | Returns | Description |
x: start x position y: start y position x2: end x position y2: end y position color: line color |
Draw a 2D line | |
void draw_circle(float x, float y, float radius, uint subdivs, ot::color color); |
||
Parameter Description | Returns | Description |
x: x position y: y position radius: circle radius subdivs: subdivisions color: circle color |
Draw a 2D circle | |
void clear(); |
||
Parameter Description | Returns | Description |
Clear the canvas | ||
void set_auto_clear(bool on); |
||
Parameter Description | Returns | Description |
on: enable or disable auto clear | Enable or disable auto clear each frame | |
void set_screen_offset(const float2& offset); |
||
Parameter Description | Returns | Description |
offset: screen offset in pixels | Set screen offset | |
void set_color(ot::color color); |
||
Parameter Description | Returns | Description |
color: Global modulation color | Set the global modulation color | |
void set_visible(bool e); |
||
Parameter Description | Returns | Description |
e: Visibility flag | Set the visibility | |
bool is_visible() const; |
||
Parameter Description | Returns | Description |
return: bool | Check if visible | |
ref<texture_2d> get_rt_texture(); |
||
Parameter Description | Returns | Description |
return: ref | Get rt texture | |