Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
skejeton committed Jul 11, 2024
1 parent 9b350ca commit 6c2c6df
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 122 deletions.
176 changes: 54 additions & 122 deletions src/staembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ const char *th_em_modulesrc[] = {
"//~~fn Image.blit\n"
"// Copies source rectangle (texture coordinates) to destination rectangle (screen coordinates).\n"
"fn (i: ^Image) blit*(src, dest: rect::Rect, color: uint32 = 0xFFFFFFFF, rot: th::fu = 0, origin: th::Vf2 = {0, 0}) {\n"
"//~~\n"
"\tumth_image_blit(i^, src, dest, color, rot, origin)\n"
"}\n"
"\n"
Expand Down Expand Up @@ -4378,194 +4379,125 @@ const char *th_em_moduledocs[] = {
"fn Image.blit\n"
"\n"
"fn (i: ^Image) blit*(src, dest: rect::Rect, color: uint32 = 0xFFFFFFFF, rot: th::fu = 0, origin: th::Vf2 = {0, 0}) {\n"
"\tumth_image_blit(i^, src, dest, color, rot, origin)\n"
"}\n"
"\n"
"fn umth_image_draw_nine_patch(img: Image, outer, inner, dest: rect::Rect,\n"
"\tcolor: uint32, scale: real)\n"
"\n"
"Copies source rectangle (texture coordinates) to destination rectangle (screen coordinates).\n"
"\n"
"---------\n"
"\n"
"[1m[0m\n"
"[1mfn Image.drawNinepatch[0m\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\tumth_image_draw_nine_patch(i^, outer, inner, dest, color, scale)\n"
"}\n"
"\n"
"fn umth_image_draw_on_quad(img: Image, color: uint32, q: th::Quad)\n"
"fn (i: ^Image) drawNinepatch*(outer, inner, dest: rect::Rect, color: uint32 = th::white, scale: real = 1.0) {\n"
"\n"
"Draws \"nine-patch\" image.\n"
"`outer` specifies the texture coordinates of the outer rect of source image,\n"
"`inner` specifies coordinates of inner rect of source image, positioned relative to `outer`.\n"
"You can tint with `color`.\n"
"\n"
"---------\n"
"![](img/ninepatch.png)\n"
"\n"
"\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"---------\n"
"\n"
"\tumth_image_draw_on_quad(i^, color, q)\n"
"}\n"
"fn Image.drawOnQuad\n"
"\n"
"fn umth_image_get_dims(i: Image): th::Vf2\n"
"[3mfn (i: ^Image) drawOnQuad*(q: th::Quad, color: uint32 = th::white) {\n"
"\n"
"Draws the image on top of a quad with corners of the image positioned\n"
"on the verticies of the quad.\n"
"\n"
"---------\n"
"\n"
"[1m[0m\n"
"[1mfn Image.getDims[0m\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\treturn umth_image_get_dims(i^)\n"
"}\n"
"\n"
"fn umth_image_crop(img: Image, tl, br: th::Vf2)\n"
"fn (i: ^Image) getDims*(): th::Vf2 {\n"
"\n"
"Returns width and heigth.\n"
"\n"
"---------\n"
"\n"
"\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\tumth_image_crop(i^, tl, br)\n"
"}\n"
"fn Image.crop\n"
"\n"
"fn (i: ^Image) crop*(tl, br: th::Vf2) {\n"
"\n"
"Crops an image. Coordinates are between 0, 0 (top left) and\n"
"1, 1 (bottom right)\n"
"\n"
"---------\n"
"\n"
"\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\tdm := i.getDims()\n"
"\tumth_image_crop(i^, tr.div(dm), br.div(dm))\n"
"}\n"
"fn Image.cropPx\n"
"\n"
"fn (i: ^Image) cropPx*(tr, br: th::Vf2) {\n"
"\n"
"Same as `Image.crop`, but the positions are in pixels.\n"
"\n"
"---------\n"
"\n"
"\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\tdm := i.getDims()\n"
"\tumth_image_crop(i^, r.getPos().div(dm), r.getEnd().div(dm))\n"
"}\n"
"fn Image.cropRect\n"
"\n"
"fn umth_image_crop_quad(img: Image, q: th::Quad)\n"
"[3mfn (i: ^Image) cropRect*(r: rect::Rect) {\n"
"\n"
"Same as `Image.crop`, but uses a rect instead of two positions.\n"
"\n"
"---------\n"
"\n"
"\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\tumth_image_crop_quad(i^, q)\n"
"}\n"
"fn Image.cropQuad\n"
"\n"
"fn umth_image_get_crop_quad(img: Image): th::Quad\n"
"[3mfn (i: ^Image) cropQuad*(q: th::Quad) {\n"
"\n"
"Crop an image using a quad.\n"
"\n"
"---------\n"
"\n"
"[1m[0m\n"
"[1mfn Image.getCropQuad[0m\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\treturn umth_image_get_crop_quad(i^)\n"
"}\n"
"\n"
"fn umth_image_from_data(ret: ^Image, data: ^uint32, dm: th::Vf2): th::ErrCode\n"
"fn (i: ^Image) getCropQuad*(): th::Quad {\n"
"\n"
"Crop an image using a quad.\n"
"\n"
"---------\n"
"\n"
"\n"
"\n"
"\timg := Image{}\n"
"\tec := umth_image_from_data(&img, &data[0], dm)\n"
"\n"
"\treturn img, th::__errFromCode(ec)\n"
"}\n"
"fn mk\n"
"\n"
"fn umth_image_copy(ret: ^Image, data: Image): th::ErrCode\n"
"[3mfn mk*(data: []uint32, dm: th::Vf2): (Image, std::Err) {\n"
"\n"
"Creates an image from raw data.\n"
"\n"
"---------\n"
"\n"
"\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\timg := Image{}\n"
"\tec := umth_image_copy(&img, i^)\n"
"fn Image.copy\n"
"\n"
"\treturn img, th::__errFromCode(ec)\n"
"}\n"
"\n"
"fn umth_image_set_filter(data: Image, filter: int): th::ErrCode\n"
"fn (i: ^Image) copy*(): (Image, std::Err) {\n"
"\n"
"Copies image into a new one.\n"
"\n"
"---------\n"
"\n"
"\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t}\n"
"\n"
"\treturn th::__errFromCode(umth_image_set_filter(i^, filter))\n"
"}\n"
"fn Image.setfilter\n"
"\n"
"fn umth_image_update_data(img: Image, data: ^uint32, dm: th::Vf2): th::ErrCode\n"
"[3mfn (i: ^Image) setfilter*(filter: int): std::Err {\n"
"\n"
"Sets a mag/min filter. 0 is nearest, others are linear.\n"
"This function will regenerate the texture. This means it shouldn\'t be\n"
"used in a loop.\n"
"https://learnopengl.com/img/getting-started/texture_filtering.png\n"
"left is nearest, right is linear.\n"
"\n"
"---------\n"
"\n"
"\n"
"\n"
"\tif !i.validate() {\n"
"\t\tth::__error(\"image is invalid\")\n"
"\t\treturn {}\n"
"\t}\n"
"\n"
"\tif dm.x * dm.y != len(data) {\n"
"\t\treturn th::__errFromCode(.bad_input, \"incorrect dimensions\")\n"
"\t}\n"
"fn Image.setData\n"
"\n"
"\treturn th::__errFromCode(umth_image_update_data(i^, &data[0], dm))\n"
"}\n"
"\n"
"fn umth_image_get_data(img: Image, data: ^uint32)\n"
"fn (i: ^Image) setData*(data: []uint32, dm: th::Vf2): std::Err {\n"
"\n"
"Updates the image data. dm are the dimensions of the new image.\n"
"The new image doesn\'t have to be the same size as the old one.\n"
"\n"
"---------\n"
"\n"
"[1m[0m\n"
"[1mfn Image.getData[0m\n"
"\n"
"\n"
"fn (i: ^Image) getData*(): []uint32 {\n"
"\n"
"Gets the image data. This downloads the data from the GPU on **each call**.\n"
"Don\'t use in performance critical sections.\n"
"\n"
"---------\n"
"\n"
Expand Down
1 change: 1 addition & 0 deletions umka/image.um
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ fn umth_image_blit(img: Image, src, dest: rect::Rect, color: uint32, rot: th::fu
//~~fn Image.blit
// Copies source rectangle (texture coordinates) to destination rectangle (screen coordinates).
fn (i: ^Image) blit*(src, dest: rect::Rect, color: uint32 = 0xFFFFFFFF, rot: th::fu = 0, origin: th::Vf2 = {0, 0}) {
//~~
umth_image_blit(i^, src, dest, color, rot, origin)
}

Expand Down

0 comments on commit 6c2c6df

Please sign in to comment.