Skip to content

Drawing

willmexe edited this page May 29, 2022 · 17 revisions

Namespace: Fjord.Modules.Graphics

class: draw

Drawing Shapes

Rectangle

  • Function
void rect(V4 rect, V4 color, bool fill=true, int border_radius=0, int depth=0, draw_origin origin=draw_origin.CENTER)  
  • Example
rect(new V4(0, 0, 100, 100), new V4(255, 0, 0, 255), true, 10, 0, draw_origin.TOP_LEFT)

This Example will draw a filled red rectangle at (0, 0) with a width of 100 and a height of 100 with the border radius 10 at a depth of 0 with an anchor point at the top left corner.

Circle

  • Function
void circle(V2 position, int radius, V4 color, bool fill=true)
  • Example
circle(new V2(50, 50), 50, new V4(255, 0, 0, 255), true)

This Example will draw a filled red circle at (50, 50) with a radius of 50 and therefor a width of 100.

Quarter

  • Function
void quarter(V2 position, int radius, draw_quarter quarter, V4 color, bool fill=true)
  • Example
quarter(new V2(50, 50), 50, draw_quarter.TOP_LEFT, new V4(255, 0, 0, 255), true)

This Example will draw a filled red circle at (50, 50) with a radius of 50 but with only the top left corner showing.

Line

  • Function
void line(V2 position, V2 position_2, V4 color)
  • Example
line(new V2(0, 0), new V2(50, 50), new V4(255, 0, 0, 255))

This Example will draw a 1 pixel wide line from (0, 0) to (50, 50).

Drawing Textures

Texture

  • Function
void texture(V2 position, texture tex)
  • Example
texture(new V2(0, 0), player_texture)

This Example will draw a texture named 'player_texture' at (0, 0). More about textures in the texture chapter.

Texture_Direct

  • Function
void texture_direct(V2 position, texture tex)
  • Example
texture_direct(new V2(0, 0), player_texture)

This Example will directly draw the texture 'player_texture' at (0, 0) to the SDL2 renderer. This Function should never be used please refer to the 'texture' Function documented above.

Get_Texture_Buffer

  • Function
List<texture_buffer> get_texture_buffer()
  • Example
List<texture_buffer> buffer = draw.get_texture_buffer()

Returns the current texture buffer used by the 'texture' Function. Only used in engine and is not needed outside in a normal project.

Clean_Texture_Buffer

  • Function
void clean_texture_buffer()
  • Example
clean_texture_buffer()

This Example cleans the texture buffer. This will clean all current waiting textures and will make them not render. DO NOT use as it will stop textures from drawing.

Text

  • Function
void text(V2 position, string font_id, int font_size, string text, V4 color)
  • Example
text(new V2(0, 0), "Sans", 24, "Hello World!", new V4(255, 0, 0, 255))

This Example will draw a red "Hello World!" with the ttf font 'Sans' from the assets/fonts folder with the font size 24 at (0, 0).

Get_Text_Texture

  • Function
IntPtr get_text_texture(string font_id, string text, V4 color)
  • Example
IntPtr hello_world_texture = draw.get_text_texture("Sans", "Hello World!", new V4(255, 0, 0, 255))

This Example will return a red "Hello World!" with the ttf font 'Sans' from the assets/fonts folder texture.

Get_Text_Rect

  • Function
V4 get_text_rect(V2 position, string font_id, int font_size, string text)
  • Example
V4 hello_world_rect = draw.get_texture_rect(new V2(0, 0), "Sans", 24, "Hello World!")

This Example will return the rectangle for a "Hello World!" with the ttf font 'Sans' from the assets/fonts folder with a font size of 24 at (0, 0).

Load_Font

  • Function
void load_font(string font_id)
  • Example
load_font("Sans")

This Example will preload a ttf font named 'Sans' from the assets/fonts directory.