Karl Zylinski 2 сар өмнө
parent
commit
23a9c784b7
2 өөрчлөгдсөн 67 нэмэгдсэн , 0 устгасан
  1. 41 0
      karl2d.doc.odin
  2. 26 0
      karl2d.odin

+ 41 - 0
karl2d.doc.odin

@@ -145,20 +145,34 @@ mouse_button_went_up :: proc(button: Mouse_Button) -> bool
 // `button` parameter. Set when 'process_events' runs.
 mouse_button_is_held :: proc(button: Mouse_Button) -> bool
 
+// Returns how many clicks the mouse wheel has scrolled between the previous and current frame.
 get_mouse_wheel_delta :: proc() -> f32
 
+// Returns the mouse position, measured from the top-left corner of the window.
 get_mouse_position :: proc() -> Vec2
 
+// Returns how many pixels the mouse moved between the previous and the current frame.
 get_mouse_delta :: proc() -> Vec2
 
+// Returns true if a gamepad with the supplied index is connected. The parameter should be a value
+// between 0 and MAX_GAMEPADS.
 is_gamepad_active :: proc(gamepad: Gamepad_Index) -> bool
 
+// Returns true if a gamepad button went down between the previous and the current frame.
 gamepad_button_went_down :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
 
+// Returns true if a gamepad button went up (was released) between the previous and the current
+// frame.
 gamepad_button_went_up :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
 
+// Returns true if a gamepad button is currently held down.
+//
+// The "trigger buttons" on some gamepads also have an analogue "axis value" associated with them.
+// Fetch that value using `get_gamepad_axis()`.
 gamepad_button_is_held :: proc(gamepad: Gamepad_Index, button: Gamepad_Button) -> bool
 
+// Returns the value of analogue gamepad axes such as the thumbsticks and trigger buttons. The value
+// is in the range -1 to 1 for sticks and 0 to 1 for trigger buttons.
 get_gamepad_axis :: proc(gamepad: Gamepad_Index, axis: Gamepad_Axis) -> f32
 
 // Set the left and right vibration motor speed. The range of left and right is 0 to 1. Note that on
@@ -169,24 +183,51 @@ set_gamepad_vibration :: proc(gamepad: Gamepad_Index, left: f32, right: f32)
 //---------//
 // DRAWING //
 //---------//
+
+// Draw a colored rectangle. The rectangles have their (x, y) position in the top-left corner of the
+// rectangle.
 draw_rect :: proc(r: Rect, c: Color)
 
+// Creates a rectangle from a position and a size and draws it.
 draw_rect_vec :: proc(pos: Vec2, size: Vec2, c: Color)
 
+// Draw a rectangle with a custom origin and rotation.
+
+// The origin says which point the rotation rotates around. If the origin is `(0, 0)`, then the
+// rectangle rotates around the top-left corner of the rectangle. If it is `(rect.w/2, rect.h/2)`
+// then the rectangle rotates around its center.
 draw_rect_ex :: proc(r: Rect, origin: Vec2, rot: f32, c: Color)
 
+// Draw the outline of a rectangle with a specific thickness. The outline is drawn using four
+// rectangles.
 draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color)
 
+// Draw a circle with a certain center and radius. Note the `segments` parameter: This circle is not
+// perfect! It is drawn using a number of "cake segments".
 draw_circle :: proc(center: Vec2, radius: f32, color: Color, segments := 16)
 
+// Like `draw_circle` but only draws the outer edge of the circle.
 draw_circle_outline :: proc(center: Vec2, radius: f32, thickness: f32, color: Color, segments := 16)
 
+// Draws a line from `start` to `end` of a certain thickness.
 draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color)
 
+// Draw a texture at a specific position. The texture will be drawn with its top-left corner at
+// position `pos`.
+//
+// Load textures using `load_texture_from_file` or `load_texture_from_bytes`.
 draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE)
 
+// Draw a section of a texture at a specific position. `rect` is a rectangle measured in pixels. It
+// tells the procedure which part of the texture to display. The texture will be drawn with its
+// top-left corner at position `pos`.
 draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE)
 
+// Draw a texture by taking a section of the texture specified by `src` and draw it into the area of
+// the screen specified by `dst`. You can also rotate the texture around an origin point of your
+// choice.
+//
+// Tip: Use `k2.get_texture_rect(tex)` for `src` if you want to draw the whole texture.
 draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotation: f32, tint := WHITE)
 
 measure_text :: proc(text: string, font_size: f32) -> Vec2

+ 26 - 0
karl2d.odin

@@ -488,6 +488,8 @@ set_gamepad_vibration :: proc(gamepad: Gamepad_Index, left: f32, right: f32) {
 // DRAWING //
 //---------//
 
+// Draw a colored rectangle. The rectangles have their (x, y) position in the top-left corner of the
+// rectangle.
 draw_rect :: proc(r: Rect, c: Color) {
 	if s.vertex_buffer_cpu_used + s.batch_shader.vertex_size * 6 > len(s.vertex_buffer_cpu) {
 		draw_current_batch()
@@ -509,10 +511,16 @@ draw_rect :: proc(r: Rect, c: Color) {
 	batch_vertex({r.x, r.y + r.h, z}, {0, 1}, c)
 }
 
+// Creates a rectangle from a position and a size and draws it.
 draw_rect_vec :: proc(pos: Vec2, size: Vec2, c: Color) {
 	draw_rect({pos.x, pos.y, size.x, size.y}, c)
 }
 
+// Draw a rectangle with a custom origin and rotation.
+
+// The origin says which point the rotation rotates around. If the origin is `(0, 0)`, then the
+// rectangle rotates around the top-left corner of the rectangle. If it is `(rect.w/2, rect.h/2)`
+// then the rectangle rotates around its center.
 draw_rect_ex :: proc(r: Rect, origin: Vec2, rot: f32, c: Color) {
 	if s.vertex_buffer_cpu_used + s.batch_shader.vertex_size * 6 > len(s.vertex_buffer_cpu) {
 		draw_current_batch()
@@ -572,6 +580,8 @@ draw_rect_ex :: proc(r: Rect, origin: Vec2, rot: f32, c: Color) {
 	batch_vertex(vec3(bl, z), {0, 1}, c)
 }
 
+// Draw the outline of a rectangle with a specific thickness. The outline is drawn using four
+// rectangles.
 draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color) {
 	t := thickness
 	
@@ -611,6 +621,8 @@ draw_rect_outline :: proc(r: Rect, thickness: f32, color: Color) {
 	draw_rect(right, color)
 }
 
+// Draw a circle with a certain center and radius. Note the `segments` parameter: This circle is not
+// perfect! It is drawn using a number of "cake segments".
 draw_circle :: proc(center: Vec2, radius: f32, color: Color, segments := 16) {
 	if s.vertex_buffer_cpu_used + s.batch_shader.vertex_size * 3 * segments > len(s.vertex_buffer_cpu) {
 		draw_current_batch()
@@ -638,6 +650,7 @@ draw_circle :: proc(center: Vec2, radius: f32, color: Color, segments := 16) {
 	}
 }
 
+// Like `draw_circle` but only draws the outer edge of the circle.
 draw_circle_outline :: proc(center: Vec2, radius: f32, thickness: f32, color: Color, segments := 16) {
 	prev := center + {radius, 0}
 	for s in 1..=segments {
@@ -649,6 +662,7 @@ draw_circle_outline :: proc(center: Vec2, radius: f32, thickness: f32, color: Co
 	}
 }
 
+// Draws a line from `start` to `end` of a certain thickness.
 draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color) {
 	p := Vec2{start.x, start.y + thickness*0.5}
 	s := Vec2{linalg.length(end - start), thickness}
@@ -661,6 +675,10 @@ draw_line :: proc(start: Vec2, end: Vec2, thickness: f32, color: Color) {
 	draw_rect_ex(r, origin, rot * math.DEG_PER_RAD, color)
 }
 
+// Draw a texture at a specific position. The texture will be drawn with its top-left corner at
+// position `pos`.
+//
+// Load textures using `load_texture_from_file` or `load_texture_from_bytes`.
 draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE) {
 	draw_texture_ex(
 		tex,
@@ -672,6 +690,9 @@ draw_texture :: proc(tex: Texture, pos: Vec2, tint := WHITE) {
 	)
 }
 
+// Draw a section of a texture at a specific position. `rect` is a rectangle measured in pixels. It
+// tells the procedure which part of the texture to display. The texture will be drawn with its
+// top-left corner at position `pos`.
 draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE) {
 	draw_texture_ex(
 		tex,
@@ -683,6 +704,11 @@ draw_texture_rect :: proc(tex: Texture, rect: Rect, pos: Vec2, tint := WHITE) {
 	)
 }
 
+// Draw a texture by taking a section of the texture specified by `src` and draw it into the area of
+// the screen specified by `dst`. You can also rotate the texture around an origin point of your
+// choice.
+//
+// Tip: Use `k2.get_texture_rect(tex)` for `src` if you want to draw the whole texture.
 draw_texture_ex :: proc(tex: Texture, src: Rect, dst: Rect, origin: Vec2, rotation: f32, tint := WHITE) {
 	if tex.width == 0 || tex.height == 0 {
 		return