From 6c2c6dfa4e96414d6d0b0192811c4adb7357aa2a Mon Sep 17 00:00:00 2001 From: skejeton Date: Thu, 11 Jul 2024 19:40:25 -0300 Subject: [PATCH] Fix documentation --- src/staembed.c | 176 +++++++++++++++---------------------------------- umka/image.um | 1 + 2 files changed, 55 insertions(+), 122 deletions(-) diff --git a/src/staembed.c b/src/staembed.c index 85704ef..74692c1 100644 --- a/src/staembed.c +++ b/src/staembed.c @@ -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" @@ -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" -"\n" +"fn Image.drawNinepatch\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" +"fn (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" -"\n" +"fn Image.getDims\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" +"fn (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" +"fn (i: ^Image) cropQuad*(q: th::Quad) {\n" "\n" +"Crop an image using a quad.\n" "\n" "---------\n" "\n" -"\n" +"fn Image.getCropQuad\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" +"fn 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" +"fn (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" -"\n" +"fn Image.getData\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" diff --git a/umka/image.um b/umka/image.um index 6c6bca0..134543b 100644 --- a/umka/image.um +++ b/umka/image.um @@ -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) }