Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Cursor types

type Cursor* = enum {
	system = 0		// Default system cursor
	arrow			// Normal cursor; Arrow cursor
	iBeam			// 'I' text cursor; I-Beam
	crosshair		// '+' cursor; Select region cursor
	finger			// Index finger pointing cursor; Click cursor
	sizeEW			// '<->' cursor; Resize width cursor; Resize horizontally cursor; East-West resize cursor
	sizeNS			// Resize height cursor; Resize vertically cursor; North-South resize cursor
	sizeNWSE			// Resize width and height from the right side cursor; Northwest-Southeast resize cursor
	sizeSWNE			// Resize width and height from the left side cursor; Southwest-Northeast resize cursor
	sizeAll			// Resize all cursor; Move cursor
	no			// '(/)' cursor; Disabled cursor; Disallowed cursor
	count_
}

Window setup options

type WindowSetupOptions* = struct {
	hidden: bool // hide by default
}




fn umth_window_setup(title: str, w, h: int)
fn umth_window_set_hidden(hidden: bool)
fn umth_window_get_dimensions(w, h: ^int32)

fn umth_window_set_viewport(dm: th::Vf2)

	wp = dm
	umth_window_set_viewport(dm)
}

fn setIcon*(img: image::Image)

fn umth_window_is_dpi_enabled(): bool

	return umth_window_is_dpi_enabled()
}

fn umth_window_get_dpi_scale(): th::fu

	return umth_window_get_dpi_scale()
}

// 0 = other/unknown
// 1 = linux
// 2 = windows
// 3 = macos (unsupported currently)
// 4 = emscripten
fn umth_window_get_platform_id(): th::Platform

	w, h = width, height
	umth_window_setup(title, width, height)
	if options.hidden {
		umth_window_set_hidden(true)
	}

	th::platform = umth_window_get_platform_id()

	audio::__setup()
	placeholders::__setup()

	setIcon(placeholders::icon)

	clockOffset = std::clock() * 1000
	start = std::clock() * 1000

	setViewport({width, height})
}

	umth_window_set_hidden(hide)
}

fn cycle(delta: real) {
	umth_window_set_viewport(wp)

	th::delta = trunc(delta*1000.0)
	if th::delta == 0 {
		th::delta = 1
	}

	start = std::clock()*1000
	th::time = round(start - clockOffset)

	umth_window_get_dimensions(&w, &h)

	audio::__cycle()
	canvas::drawRect(th::white, rect::mk(0, 0, wp.x, wp.y))
}

fn setViewportOffset*(s: th::Vf2)
fn getViewportOffset*(): th::Vf2

fn drawClear() {
	of := getViewportOffset()
	setViewportOffset({})
	canvas::drawRect(th::black, rect::mk(-4 * wp.x, 0, 4 * wp.x, wp.y))
	canvas::drawRect(th::black, rect::mk(0, -4 * wp.y, wp.x, 4 * wp.y))
	canvas::drawRect(th::black, rect::mk(wp.x, 0, 4 * wp.x, wp.y))
	canvas::drawRect(th::black, rect::mk(0, wp.y, wp.x, 4 * wp.y))
	setViewportOffset(of)
}

fn umth_frame_callback*(delta: real) {
	cycle(delta)
	onFrame.emit(null)
	drawClear()
}

fn umth_destroy_callback*() {
  onDestroy.emit(null)
}

fn umth_window_set_fullscreen(fullscreen: bool)
fn umth_window_get_fullscreen(): bool

	umth_window_set_fullscreen(fullscreen)
}

	return umth_window_get_fullscreen()
}

	return {w, h}
}

fn umth_window_set_target_fps(fps: int)

	fpsLimit = fps
	umth_window_set_target_fps(fps)
}

fn umth_window_set_title(title: str)

	umth_window_set_title(title)
}

fn umth_window_set_dims(dm: th::Vf2)

	umth_window_set_dims(dm)
}

fn umth_window_set_icon(img: image::Image)

	if !img.validate() {
		th::__error("invalid image")
	}

	umth_window_set_icon(img)
}

fn umth_window_show_cursor(show: bool)

	umth_window_show_cursor(show)
}

fn umth_window_freeze_cursor(freeze: bool)

	showCursor(freeze)
	umth_window_freeze_cursor(freeze)
}

fn umth_window_set_cursor(cursor: Cursor)

	umth_window_set_cursor(cursor);
}

fn umth_window_request_exit()

	umth_window_request_exit()
}

fn umth_window_set_clipboard(s: str)

	umth_window_set_clipboard(s)
}

fn umth_window_get_clipboard(): str

	return umth_window_get_clipboard()
}

fn umth_window_set_viewport_offset(s: th::Vf2)

	umth_window_set_viewport_offset(s)
}

fn umth_window_get_viewport_offset(): th::Vf2