Skip to content

Commit

Permalink
Cleanup initializer
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Maškarinec <[email protected]>
  • Loading branch information
marekmaskarinec committed Apr 18, 2024
1 parent 1a88148 commit 9b349ea
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion examples/hello-world/main.um
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 18 additions & 18 deletions src/staembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions umka/atlas.um
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
Expand Down Expand Up @@ -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 {}
}
10 changes: 5 additions & 5 deletions umka/canvas.um
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions umka/ent.um
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion umka/input.um
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions umka/rect.um
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion umka/ui.um
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions umka/window.um
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9b349ea

Please sign in to comment.