Skip to content

image.um

Marek Maskarinec edited this page Oct 9, 2022 · 7 revisions

image.um

struct Image*

type Image* = struct{ _: ^struct{} }

Represents a drawable image. It is an opaque structure. Images support a color filter. It is applied by multiplying the color of each pixel with the filter.

fn load*

fn load*(path: str): Image {

Loads an image at path.

fn flipv*

fn (i: ^Image) flipv*(flip: bool) {

Flips image on it's vertical axis.

fn fliph*

fn (i: ^Image) fliph*(flip: bool) {

Flips image on it's horizontal axis.

fn draw*

fn (i: ^Image) draw*(t: th.Transform, color: uint32 = th.white) {

Draws the image in screen coordinates. It transforms it with t and applies color as a color filter.

fn drawNinepatch*

fn (i: ^Image) drawNinepatch*(outer, inner, dest: rect.Rect, color: uint32 = th.white) {

Draws "nine-patch" image. outer specifies the texture coordinates of the outer rect of source image, inner specifies coordinates of inner rect of source image, positioned relative to outer. You can tint with color.

fn drawOnQuad*

fn (i: ^Image) drawOnQuad*(q: th.Quad, color: uint32 = th.white) {

Draws the image on top of a quad with corners of the image positioned on the verticies of the quad.

fn validate*

fn (i: ^Image) validate*(): bool {

Returns true, if i's handle points to an image.

fn getDims*

fn (i: ^Image) getDims*(): th.Vf2 {

Returns width and heigth.

fn crop*

fn (i: ^Image) crop*(tl, br: th.Vf2) {

Crops an image. Coordinates are between 0, 0 (top left) and 1, 1 (bottom right)

fn cropQuad*

fn (i: ^Image) cropQuad*(q: th.Quad) {

Crop an image using a quad.

fn getCropQuad*

fn (i: ^Image) getCropQuad*(): th.Quad {

Crop an image using a quad.

fn mk*

fn mk*(data: []uint32, dm: th.Vf2): Image {

Creates an image from raw data.

fn copy*

fn (i: ^Image) copy*(): Image {

Copies image into a new one.

fn setfilter*

fn (i: ^Image) setfilter*(filter: int) {

Sets a mag/min filter. 0 is linear, others are nearest. This function will regenerate the texture. This means it shouldn't be used in a loop. https://learnopengl.com/img/getting-started/texture_filtering.png left is nearest, right is linear.

fn setData*

fn (i: ^Image) setData*(data: []uint32, dm: th.Vf2) {

Updates the image data. dm are the dimensions of the new image. The new image doesn't have to be the same size as the old one.

fn getData*

fn (i: ^Image) getData*(): []uint32 {

Gets the image data.

fn makeRenderTarget*

fn (i: ^Image) makeRenderTarget*() {

Sets the image a the render target. This means stuff won't be drawn onto the screen, but into the image. In this mode, the scaling is always 1. An the resolution of the screen are the image's dimensions.

fn removeRenderTarget*

fn (i: ^Image) removeRenderTarget*(cam: rect.Rect) {

Returns to rendering onto the screen.

Clone this wiki locally