From 9b349eaf50e9268978956c2405aad22d2357d10a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ma=C5=A1karinec?= Date: Thu, 18 Apr 2024 20:17:36 +0100 Subject: [PATCH] Cleanup initializer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marek Maškarinec --- examples/hello-world/main.um | 2 +- src/staembed.c | 36 ++++++++++++++++++------------------ umka/atlas.um | 6 +++--- umka/canvas.um | 10 +++++----- umka/ent.um | 4 ++-- umka/input.um | 2 +- umka/rect.um | 6 +++--- umka/ui.um | 2 +- umka/window.um | 4 ++-- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/examples/hello-world/main.um b/examples/hello-world/main.um index 43b3752..494e1f9 100644 --- a/examples/hello-world/main.um +++ b/examples/hello-world/main.um @@ -11,7 +11,7 @@ fn init*() { window::setup("title", 400, 400) window::setViewport(th::Vf2{400, 400}) - window.onFrame.register({ + window::onFrame.register({ canvas::drawRect(th::blue, rect::mk(0, 0, window::wp.x, window::wp.y)) canvas::drawText("hello world", th::Vf2{2, 2}, th::white, 4) diff --git a/src/staembed.c b/src/staembed.c index 7376e5a..e982b05 100644 --- a/src/staembed.c +++ b/src/staembed.c @@ -439,7 +439,7 @@ const char *th_em_modulesrc[] = { "\n" "//~~fn mk\n" "// ent\'s constructor\n" -"fn mk*(img: image::Image = image::Image{}, t: th::Transform = th::Transform{ s: th::Vf2{1, 1} }): Ent {\n" +"fn mk*(img: image::Image = image::Image{}, t: th::Transform = th::Transform{ s: {1, 1} }): Ent {\n" "//~~\n" "\tvar e: Ent\n" "\te.i = img\n" @@ -452,7 +452,7 @@ const char *th_em_modulesrc[] = { "\te.c = th::white\n" "\n" "\tif t.s.x == 0 && t.s.y == 0 {\n" -"\t\tt.s = th::Vf2{ 1, 1 }\n" +"\t\tt.s = { 1, 1 }\n" "\t}\n" "\n" "\treturn e\n" @@ -1105,7 +1105,7 @@ const char *th_em_modulesrc[] = { "\t//~~\n" "\tvar x, y: th::fu\n" "\tumth_input_get_mouse_scroll(&x, &y)\n" -"\treturn th::Vf2{x, y}\n" +"\treturn {x, y}\n" "}\n" "\n" "fn umth_input_gamepad_get_gamepads*(out: ^[4]int)\n" @@ -1278,7 +1278,7 @@ const char *th_em_modulesrc[] = { "\t\tmaxw = w\n" "\t}\n" "\n" -"\treturn th::Vf2{maxw * scale * 6 - scale, h * 6 * scale}\n" +"\treturn {maxw * scale * 6 - scale, h * 6 * scale}\n" "}\n" "\n" "fn umth_canvas_draw_rect(color: uint32, r: rect::Rect)\n" @@ -1302,13 +1302,13 @@ const char *th_em_modulesrc[] = { "fn drawRectLines*(color: uint32, r: rect::Rect, thickness: real32 = 1.0) {\n" "//~~\n" " // top\n" -" drawLine(color, th::Vf2{r.x-1, r.y}, th::Vf2{r.x+r.w, r.y}, thickness)\n" +" drawLine(color, {r.x-1, r.y}, {r.x+r.w, r.y}, thickness)\n" " // bottom\n" -" drawLine(color, th::Vf2{r.x, r.y+r.h}, th::Vf2{r.x+r.w, r.y+r.h}, thickness)\n" +" drawLine(color, {r.x, r.y+r.h}, {r.x+r.w, r.y+r.h}, thickness)\n" " // left\n" -" drawLine(color, th::Vf2{r.x, r.y}, th::Vf2{r.x, r.y+r.h}, thickness)\n" +" drawLine(color, {r.x, r.y}, {r.x, r.y+r.h}, thickness)\n" " // right\n" -" drawLine(color, th::Vf2{r.x+r.w, r.y}, th::Vf2{r.x+r.w, r.y+r.h}, thickness)\n" +" drawLine(color, {r.x+r.w, r.y}, {r.x+r.w, r.y+r.h}, thickness)\n" "}\n" "\n" "fn umth_canvas_draw_quad(color: uint32, q: ^th::Quad)\n" @@ -1404,20 +1404,20 @@ const char *th_em_modulesrc[] = { "//~~fn Rect.getPos\n" "fn (r: ^Rect) getPos*(): th::Vf2 {\n" "//~~\n" -"\treturn th::Vf2{r.x, r.y}\n" +"\treturn {r.x, r.y}\n" "}\n" "\n" "//~~fn Rect.getDims\n" "fn (r: ^Rect) getDims*(): th::Vf2 {\n" "//~~\n" -"\treturn th::Vf2{r.w, r.h}\n" +"\treturn {r.w, r.h}\n" "}\n" "\n" "//~~fn Rect.getEnd\n" "// returns where the second point of the rectangle lies.\n" "fn (r: ^Rect) getEnd*(): th::Vf2 {\n" "//~~\n" -"\treturn th::Vf2{r.x+r.w, r.y+r.h}\n" +"\treturn {r.x+r.w, r.y+r.h}\n" "}\n" "\n" "fn umth_transform_rect(ret: ^th::Quad, r: ^Rect, t: ^th::Transform)\n" @@ -1700,7 +1700,7 @@ const char *th_em_modulesrc[] = { "\tclockOffset = std::clock() * 1000\n" "\tstart = std::clock() * 1000\n" "\n" -"\tsetViewport(th::Vf2{width, height})\n" +"\tsetViewport({width, height})\n" "}\n" "\n" "//~~fn cycle\n" @@ -1768,7 +1768,7 @@ const char *th_em_modulesrc[] = { "// Returns dimensions of the window in screen pixels.\n" "fn getDims*(): th::Vf2 {\n" "//~~\n" -"\treturn th::Vf2{w, h}\n" +"\treturn {w, h}\n" "}\n" "\n" "fn umth_window_set_target_fps(fps: int)\n" @@ -2663,8 +2663,8 @@ const char *th_em_modulesrc[] = { "\t}\n" "\n" "\ta.i.crop(\n" -"\t\tth::Vf2{at.x / a.dm.x, at.y / a.dm.y},\n" -"\t\tth::Vf2{(at.x+1) / a.dm.x, (at.y+1) / a.dm.y})\n" +"\t\t{at.x / a.dm.x, at.y / a.dm.y},\n" +"\t\t{(at.x+1) / a.dm.x, (at.y+1) / a.dm.y})\n" "\n" "\treturn {}\n" "}\n" @@ -2698,7 +2698,7 @@ const char *th_em_modulesrc[] = { "\n" "\ta.cropSource(at)\n" "\ta.i.draw(t, th::white)\n" -"\ta.i.crop(th::Vf2{}, th::Vf2{1, 1})\n" +"\ta.i.crop({}, {1, 1})\n" "\n" "\treturn {}\n" "}\n" @@ -3674,7 +3674,7 @@ const char *th_em_modulesrc[] = { "\t\ty += (r.h-txtSize.y)/2.0\n" "\t}\n" "\n" -"\tstyle.ft.draw(text, th::Vf2{x, y},\n" +"\tstyle.ft.draw(text, {x, y},\n" "\t\tstyle.ftColor, style.ftScale)\n" "}\n" "\n" @@ -4306,7 +4306,7 @@ const char *th_em_moduledocs[] = { "## fn mk\n" "\n" "```\n" -"fn mk*(img: image::Image = image::Image{}, t: th::Transform = th::Transform{ s: th::Vf2{1, 1} }): Ent {\n" +"fn mk*(img: image::Image = image::Image{}, t: th::Transform = th::Transform{ s: {1, 1} }): Ent {\n" "```\n" "\n" "ent\'s constructor\n" diff --git a/umka/atlas.um b/umka/atlas.um index 38f1700..ba376cc 100644 --- a/umka/atlas.um +++ b/umka/atlas.um @@ -52,8 +52,8 @@ fn (a: ^Atlas) cropSource*(at: th::Vf2): std::Err { } a.i.crop( - th::Vf2{at.x / a.dm.x, at.y / a.dm.y}, - th::Vf2{(at.x+1) / a.dm.x, (at.y+1) / a.dm.y}) + {at.x / a.dm.x, at.y / a.dm.y}, + {(at.x+1) / a.dm.x, (at.y+1) / a.dm.y}) return {} } @@ -87,7 +87,7 @@ fn (a: ^Atlas) draw*(at: th::Vf2, t: th::Transform): std::Err { a.cropSource(at) a.i.draw(t, th::white) - a.i.crop(th::Vf2{}, th::Vf2{1, 1}) + a.i.crop({}, {1, 1}) return {} } diff --git a/umka/canvas.um b/umka/canvas.um index 527838d..94f41a0 100644 --- a/umka/canvas.um +++ b/umka/canvas.um @@ -43,7 +43,7 @@ fn textSize*(text: str, scale: th::fu): th::Vf2 { maxw = w } - return th::Vf2{maxw * scale * 6 - scale, h * 6 * scale} + return {maxw * scale * 6 - scale, h * 6 * scale} } fn umth_canvas_draw_rect(color: uint32, r: rect::Rect) @@ -67,13 +67,13 @@ fn drawLine*(color: uint32, b, e: th::Vf2, thickness: th::fu) { fn drawRectLines*(color: uint32, r: rect::Rect, thickness: real32 = 1.0) { //~~ // top - drawLine(color, th::Vf2{r.x-1, r.y}, th::Vf2{r.x+r.w, r.y}, thickness) + drawLine(color, {r.x-1, r.y}, {r.x+r.w, r.y}, thickness) // bottom - drawLine(color, th::Vf2{r.x, r.y+r.h}, th::Vf2{r.x+r.w, r.y+r.h}, thickness) + drawLine(color, {r.x, r.y+r.h}, {r.x+r.w, r.y+r.h}, thickness) // left - drawLine(color, th::Vf2{r.x, r.y}, th::Vf2{r.x, r.y+r.h}, thickness) + drawLine(color, {r.x, r.y}, {r.x, r.y+r.h}, thickness) // right - drawLine(color, th::Vf2{r.x+r.w, r.y}, th::Vf2{r.x+r.w, r.y+r.h}, thickness) + drawLine(color, {r.x+r.w, r.y}, {r.x+r.w, r.y+r.h}, thickness) } fn umth_canvas_draw_quad(color: uint32, q: ^th::Quad) diff --git a/umka/ent.um b/umka/ent.um index 298e395..fccf4a4 100644 --- a/umka/ent.um +++ b/umka/ent.um @@ -41,7 +41,7 @@ fn (e: ^Ent) draw*() { //~~fn mk // ent's constructor -fn mk*(img: image::Image = image::Image{}, t: th::Transform = th::Transform{ s: th::Vf2{1, 1} }): Ent { +fn mk*(img: image::Image = image::Image{}, t: th::Transform = th::Transform{ s: {1, 1} }): Ent { //~~ var e: Ent e.i = img @@ -54,7 +54,7 @@ fn mk*(img: image::Image = image::Image{}, t: th::Transform = th::Transform{ s: e.c = th::white if t.s.x == 0 && t.s.y == 0 { - t.s = th::Vf2{ 1, 1 } + t.s = { 1, 1 } } return e diff --git a/umka/input.um b/umka/input.um index 46b3b3a..b4bbf68 100644 --- a/umka/input.um +++ b/umka/input.um @@ -303,7 +303,7 @@ fn getMouseScroll*(): th::Vf2 { //~~ var x, y: th::fu umth_input_get_mouse_scroll(&x, &y) - return th::Vf2{x, y} + return {x, y} } fn umth_input_gamepad_get_gamepads*(out: ^[4]int) diff --git a/umka/rect.um b/umka/rect.um index c9d6daf..1d37ef3 100644 --- a/umka/rect.um +++ b/umka/rect.um @@ -33,20 +33,20 @@ fn fromVf2*(p: th::Vf2, dm: th::Vf2): Rect { //~~fn Rect.getPos fn (r: ^Rect) getPos*(): th::Vf2 { //~~ - return th::Vf2{r.x, r.y} + return {r.x, r.y} } //~~fn Rect.getDims fn (r: ^Rect) getDims*(): th::Vf2 { //~~ - return th::Vf2{r.w, r.h} + return {r.w, r.h} } //~~fn Rect.getEnd // returns where the second point of the rectangle lies. fn (r: ^Rect) getEnd*(): th::Vf2 { //~~ - return th::Vf2{r.x+r.w, r.y+r.h} + return {r.x+r.w, r.y+r.h} } fn umth_transform_rect(ret: ^th::Quad, r: ^Rect, t: ^th::Transform) diff --git a/umka/ui.um b/umka/ui.um index 4abb964..fc19939 100644 --- a/umka/ui.um +++ b/umka/ui.um @@ -617,7 +617,7 @@ fn (gui: ^Gui) label*(text: str, cfg: LabelConfig = { y += (r.h-txtSize.y)/2.0 } - style.ft.draw(text, th::Vf2{x, y}, + style.ft.draw(text, {x, y}, style.ftColor, style.ftScale) } diff --git a/umka/window.um b/umka/window.um index 3bfa2f2..997e4d2 100644 --- a/umka/window.um +++ b/umka/window.um @@ -110,7 +110,7 @@ fn setup*(title: str = "tophat game", width: int = 400, height: int32 = 400) { clockOffset = std::clock() * 1000 start = std::clock() * 1000 - setViewport(th::Vf2{width, height}) + setViewport({width, height}) } //~~fn cycle @@ -178,7 +178,7 @@ fn isFullscreen*(): bool { // Returns dimensions of the window in screen pixels. fn getDims*(): th::Vf2 { //~~ - return th::Vf2{w, h} + return {w, h} } fn umth_window_set_target_fps(fps: int)