1
0
Fork 0
forked from AbleOS/ableos

broken struct method things

This commit is contained in:
koniifer 2024-12-14 16:39:45 +00:00
parent 72cf91a928
commit ee68a2662c
25 changed files with 532 additions and 595 deletions

47
Cargo.lock generated
View file

@ -73,9 +73,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.3" version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d" checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf"
dependencies = [ dependencies = [
"shlex", "shlex",
] ]
@ -213,12 +213,12 @@ dependencies = [
[[package]] [[package]]
name = "hbbytecode" name = "hbbytecode"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#71ba2c24865944bebb641fcd48afc9d87987404d" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#91e35b72eeab9c230d52ec8636faf1dc0f96554a"
[[package]] [[package]]
name = "hblang" name = "hblang"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#71ba2c24865944bebb641fcd48afc9d87987404d" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#91e35b72eeab9c230d52ec8636faf1dc0f96554a"
dependencies = [ dependencies = [
"hashbrown", "hashbrown",
"hbbytecode", "hbbytecode",
@ -229,7 +229,7 @@ dependencies = [
[[package]] [[package]]
name = "hbvm" name = "hbvm"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#71ba2c24865944bebb641fcd48afc9d87987404d" source = "git+https://git.ablecorp.us/AbleOS/holey-bytes.git#91e35b72eeab9c230d52ec8636faf1dc0f96554a"
dependencies = [ dependencies = [
"hbbytecode", "hbbytecode",
] ]
@ -421,9 +421,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.167" version = "0.2.168"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc" checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d"
[[package]] [[package]]
name = "limine" name = "limine"
@ -455,18 +455,18 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]] [[package]]
name = "logos" name = "logos"
version = "0.14.2" version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c6b6e02facda28ca5fb8dbe4b152496ba3b1bd5a4b40bb2b1b2d8ad74e0f39b" checksum = "7251356ef8cb7aec833ddf598c6cb24d17b689d20b993f9d11a3d764e34e6458"
dependencies = [ dependencies = [
"logos-derive", "logos-derive",
] ]
[[package]] [[package]]
name = "logos-codegen" name = "logos-codegen"
version = "0.14.3" version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f3303189202bb8a052bcd93d66b6c03e6fe70d9c7c47c0ea5e974955e54c876" checksum = "59f80069600c0d66734f5ff52cc42f2dabd6b29d205f333d61fd7832e9e9963f"
dependencies = [ dependencies = [
"beef", "beef",
"fnv", "fnv",
@ -474,15 +474,14 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex-syntax", "regex-syntax",
"rustc_version",
"syn", "syn",
] ]
[[package]] [[package]]
name = "logos-derive" name = "logos-derive"
version = "0.14.3" version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "774a1c225576486e4fdf40b74646f672c542ca3608160d348749693ae9d456e6" checksum = "24fb722b06a9dc12adb0963ed585f19fc61dc5413e6a9be9422ef92c091e731d"
dependencies = [ dependencies = [
"logos-codegen", "logos-codegen",
] ]
@ -594,9 +593,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.23.19" version = "0.23.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b"
dependencies = [ dependencies = [
"log", "log",
"once_cell", "once_cell",
@ -609,9 +608,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-pki-types" name = "rustls-pki-types"
version = "1.10.0" version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37"
[[package]] [[package]]
name = "rustls-webpki" name = "rustls-webpki"
@ -644,24 +643,24 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "semver" name = "semver"
version = "1.0.23" version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.215" version = "1.0.216"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.215" version = "1.0.216"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View file

@ -99,7 +99,8 @@ pub fn memory_msg_handler(
let count = u32::from_le_bytes(msg_vec[1..5].try_into().unwrap_unchecked()) as usize; let count = u32::from_le_bytes(msg_vec[1..5].try_into().unwrap_unchecked()) as usize;
let src = u64::from_le_bytes(msg_vec[5..13].try_into().unwrap_unchecked()) as *const u8; let src = u64::from_le_bytes(msg_vec[5..13].try_into().unwrap_unchecked()) as *const u8;
let dest = u64::from_le_bytes(msg_vec[13..21].try_into().unwrap_unchecked()) as *mut u8; let dest = u64::from_le_bytes(msg_vec[13..21].try_into().unwrap_unchecked()) as *mut u8;
debug_assert!(src.addr() & 0xFFFF000000000000 != 0);
debug_assert!(dest.addr() & 0xFFFF000000000000 != 0);
src.copy_to_nonoverlapping(dest, count); src.copy_to_nonoverlapping(dest, count);
}, },
5 => unsafe { 5 => unsafe {
@ -107,7 +108,8 @@ pub fn memory_msg_handler(
let size = u32::from_le_bytes(msg_vec[5..9].try_into().unwrap_unchecked()) as usize; let size = u32::from_le_bytes(msg_vec[5..9].try_into().unwrap_unchecked()) as usize;
let src = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as *const u8; let src = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap_unchecked()) as *const u8;
let dest = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *mut u8; let dest = u64::from_le_bytes(msg_vec[17..25].try_into().unwrap_unchecked()) as *mut u8;
debug_assert!(src.addr() & 0xFFFF000000000000 != 0);
debug_assert!(dest.addr() & 0xFFFF000000000000 != 0);
memset(dest, src, count, size); memset(dest, src, count, size);
}, },
_ => { _ => {

View file

@ -16,9 +16,9 @@ Label := struct {
fg: Color, fg: Color,
new_label := fn(text: ^u8, width: uint): Self { new_label := fn(text: ^u8, width: uint): Self {
text_surface := render.new_surface(width, 20) text_surface := render.Surface.new(width, 20)
text_length := string.length(text) text_length := string.length(text)
label := Self.(3, true, text_surface, text, text_length, render.black, render.white) label := Self.(3, true, text_surface, text, text_length, render.BLACK, render.WHITE)
return label return label
} }
@ -39,8 +39,8 @@ Label := struct {
render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void { render_label_to_surface := fn(surface: Surface, label: Label, font: Font, pos: Vec2(uint)): void {
if label.is_dirty { if label.is_dirty {
render.clear(label.surface, label.bg) label.surface.clear(label.bg)
render.put_text(label.surface, font, .(0, 0), label.fg, label.text) label.surface.put_text(font, .(0, 0), label.fg, label.text)
} }
render.put_surface(surface, label.surface, pos, false) surface.put_surface(label.surface, pos, false)
} }

View file

@ -4,6 +4,3 @@ Rendering interface for SVGA and Software renderers
- SVGA Driver - SVGA Driver
- needs pci driver - needs pci driver
- needs init (requiring program)
- Double Buffer mode for Software renderer
- needs init (requiring program)

View file

@ -42,8 +42,8 @@ from := fn(bmp: ^u8): ?Surface {
} }
lhs := Surface.(@bitcast(bmp + file_header.offset), info_header.width, info_header.height, info_header.width * info_header.height) lhs := Surface.(@bitcast(bmp + file_header.offset), info_header.width, info_header.height, info_header.width * info_header.height)
rhs := new_surface(info_header.width, info_header.height) rhs := Surface.new(info_header.width, info_header.height)
put_surface(rhs, lhs, .(0, 0), true) rhs.put_surface(lhs, .(0, 0), true)
return rhs return rhs
} }

View file

@ -44,7 +44,7 @@ from := fn(qoi: ^u8): ?Surface {
return null return null
} }
surface := new_surface(width, height) surface := Surface.new(width, height)
index := @as([Color; 64], idk) index := @as([Color; 64], idk)
run := 0 run := 0

View file

@ -6,52 +6,23 @@ text := @use("text.hb")
mode := software mode := software
init := mode.init init := mode.init
doublebuffer := mode.doublebuffer
Surface := mode.Surface Surface := mode.Surface
new_surface := mode.new_surface
surface_from_ptr := mode.surface_from_ptr
clone_surface := mode.clone_surface
free_surface := mode.free_surface
index := mode.index
indexptr := mode.indexptr
// Colours // Colours
Color := packed struct {b: u8, g: u8, r: u8, a: u8} Color := packed struct {b: u8, g: u8, r: u8, a: u8}
$white := Color.(255, 255, 255, 255) $WHITE := Color.(255, 255, 255, 255)
$black := Color.(0, 0, 0, 255) $BLACK := Color.(0, 0, 0, 255)
$gray := Color.(127, 127, 127, 255) $GRAY := Color.(127, 127, 127, 255)
$red := Color.(0, 0, 205, 255) $RED := Color.(0, 0, 205, 255)
$green := Color.(0, 205, 0, 255) $GREEN := Color.(0, 205, 0, 255)
$yellow := Color.(0, 205, 205, 255) $YELLOW := Color.(0, 205, 205, 255)
$blue := Color.(205, 0, 0, 255) $BLUE := Color.(205, 0, 0, 255)
$magenta := Color.(205, 0, 205, 255) $MAGENTA := Color.(205, 0, 205, 255)
$cyan := Color.(205, 205, 0, 255) $CYAN := Color.(205, 205, 0, 255)
$light_gray := Color.(229, 229, 229, 255) $LIGHT_GRAY := Color.(229, 229, 229, 255)
$light_red := Color.(0, 0, 255, 255) $LIGHT_RED := Color.(0, 0, 255, 255)
$light_green := Color.(0, 255, 0, 255) $LIGHT_GREEN := Color.(0, 255, 0, 255)
$light_yellow := Color.(0, 255, 255, 255) $LIGHT_YELLOW := Color.(0, 255, 255, 255)
$light_blue := Color.(255, 0, 0, 255) $LIGHT_BLUE := Color.(255, 0, 0, 255)
$light_magenta := Color.(255, 0, 255, 255) $LIGHT_MAGENTA := Color.(255, 0, 255, 255)
$light_cyan := Color.(255, 255, 0, 255) $LIGHT_CYAN := Color.(255, 255, 0, 255)
// Drawing
put_pixel := mode.put_pixel
put_rect := mode.put_rect
put_filled_rect := mode.put_filled_rect
put_trirect := mode.put_trirect
put_circle := mode.put_circle
put_filled_circle := mode.put_filled_circle
put_textured_circle := mode.put_textured_circle
put_line := mode.put_line
put_vline := mode.put_vline
put_hline := mode.put_hline
clear := mode.clear
put_surface := mode.put_surface
put_text := mode.put_text
// thanks peony for these three!
//put_trirect := mode.put_trirect
//put_vline := mode.put_vline
//put_hline := mode.put_hline
// Display
sync := mode.sync

View file

@ -1,459 +1,441 @@
.{math, memory, dt} := @use("../../stn/src/lib.hb"); .{math, memory, dt} := @use("stn");
.{Color, text} := @use("lib.hb"); .{Color, text} := @use("lib:render");
.{get_glyph, get_glyph_unicode, Font, UNC_TABLE_SIZE} := text; .{get_glyph, get_glyph_unicode, Font, UNC_TABLE_SIZE} := text;
.{Vec2} := math .{Vec2} := math
// safety: don't use before init() or you will get a memory access violation // safety: don't use before init() or you will get a memory access violation
framebuffer := memory.dangling(Color) framebuffer := memory.dangling(Color)
utf8_len_table := [u8].(0, 0, 2, 3)
Surface := struct {
buf: ^Color,
width: uint,
height: uint,
size: uint,
}
new_surface := fn(width: uint, height: uint): Surface {
return .(
memory.alloc(Color, width * height),
width,
height,
width * height,
)
}
clone_surface := fn(surface: ^Surface): Surface {
new := new_surface(surface.width, surface.height)
memory.copy(Color, surface.buf, new.buf, @intcast(surface.size))
return new
}
init := fn(doublebuffer: bool): Surface { init := fn(doublebuffer: bool): Surface {
framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0") framebuffer = dt.get(^Color, "framebuffer/fb0/ptr\0")
width := dt.get(uint, "framebuffer/fb0/width\0") width := dt.get(uint, "framebuffer/fb0/width\0")
height := dt.get(uint, "framebuffer/fb0/height\0") height := dt.get(uint, "framebuffer/fb0/height\0")
if doublebuffer { if doublebuffer {
return new_surface(width, height) return Surface.new(width, height)
} else { } else {
return .(framebuffer, width, height, width * height) return .(framebuffer, width, height, width * height)
} }
} }
$clear := fn(surface: Surface, color: Color): void { Surface := struct {
memory.set(Color, &color, surface.buf, surface.width * surface.height) buf: ^Color,
} width: uint,
height: uint,
size: uint,
$sync := fn(surface: Surface): void { new := fn(width: uint, height: uint): Self {
memory.copy(Color, surface.buf, framebuffer, @bitcast(surface.width * surface.height)) size := width * height
} return .(
memory.alloc(Color, size),
$index := fn(surface: Surface, x: uint, y: uint): uint { width,
return x + surface.width * y height,
} size,
)
$indexptr := fn(surface: Surface, x: uint, y: uint): ^Color {
return surface.buf + index(surface, x, y)
}
$put_pixel := fn(surface: Surface, pos: Vec2(uint), color: Color): void {
return *indexptr(surface, pos.x, pos.y) = color
}
put_filled_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): void {
top_start_idx := indexptr(surface, pos.x, pos.y)
bottom_start_idx := indexptr(surface, pos.x, pos.y + tr.y - 1)
rows_to_fill := tr.y
loop if rows_to_fill <= 1 break else {
memory.set(Color, &color, top_start_idx, tr.x)
memory.set(Color, &color, bottom_start_idx, tr.x)
top_start_idx += surface.width
bottom_start_idx -= surface.width
rows_to_fill -= 2
} }
if rows_to_fill == 1 { clone := fn(self: ^Self): Self {
memory.set(Color, &color, top_start_idx, tr.x) new_self := Self.new(self.width, self.height)
memory.copy(Color, self.buf, new_self.buf, self.size)
return new_self
}
$clear := fn(self: Self, color: Color): void {
memory.set(Color, &color, self.buf, self.size)
} }
return $sync := fn(self: Self): void {
} memory.copy(Color, self.buf, framebuffer, self.size)
put_rect := fn(surface: Surface, pos: Vec2(uint), tr: Vec2(uint), color: Color): void {
start_idx := indexptr(surface, pos.x, pos.y)
end_idx := indexptr(surface, pos.x, pos.y + tr.y)
right_start_idx := indexptr(surface, pos.x + tr.x, pos.y)
loop if start_idx > end_idx break else {
*start_idx = color;
*right_start_idx = color
start_idx += surface.width
right_start_idx += surface.width
} }
memory.set(Color, &color, indexptr(surface, pos.x, pos.y), @bitcast(tr.x + 1)) $index := fn(self: Self, x: uint, y: uint): uint {
memory.set(Color, &color, indexptr(surface, pos.x, pos.y + tr.y), @bitcast(tr.x + 1)) return x + self.width * y
return
}
put_line_low := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
dx := @as(int, @bitcast(p1.x - p0.x))
dy := @as(int, @bitcast(p1.y - p0.y))
yi := 1
if dy < 0 {
yi = -1
dy = -dy
} }
D := @as(int, 2) * dy - dx
y := p0.y $indexptr := fn(self: Self, x: uint, y: uint): ^Color {
x := p0.x return self.buf + self.index(x, y)
loop if x == p1.x break else { }
*indexptr(surface, x, y) = color
if D > 0 { $put_pixel := fn(self: Self, pos: Vec2(uint), color: Color): void {
y += yi *self.indexptr(pos.x, pos.y) = color
D += 2 * (dy - dx) }
put_filled_rect := fn(self: Self, pos: Vec2(uint), tr: Vec2(uint), color: Color): void {
top_start_idx := self.indexptr(pos.x, pos.y)
bottom_start_idx := self.indexptr(pos.x, pos.y + tr.y - 1)
rows_to_fill := tr.y
loop if rows_to_fill <= 1 break else {
memory.set(Color, &color, top_start_idx, tr.x)
memory.set(Color, &color, bottom_start_idx, tr.x)
top_start_idx += self.width
bottom_start_idx -= self.width
rows_to_fill -= 2
}
if rows_to_fill == 1 {
memory.set(Color, &color, top_start_idx, tr.x)
}
}
put_rect := fn(self: Self, pos: Vec2(uint), tr: Vec2(uint), color: Color): void {
start_idx := self.indexptr(pos.x, pos.y)
end_idx := self.indexptr(pos.x, pos.y + tr.y)
right_start_idx := self.indexptr(pos.x + tr.x, pos.y)
loop if start_idx > end_idx break else {
*start_idx = color;
*right_start_idx = color
start_idx += self.width
right_start_idx += self.width
}
memory.set(Color, &color, self.indexptr(pos.x, pos.y), @bitcast(tr.x + 1))
memory.set(Color, &color, self.indexptr(pos.x, pos.y + tr.y), @bitcast(tr.x + 1))
}
put_line_low := fn(self: Self, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
dx := @as(int, @bitcast(p1.x - p0.x))
dy := @as(int, @bitcast(p1.y - p0.y))
yi := 1
if dy < 0 {
yi = -1
dy = -dy
}
D := @as(int, 2) * dy - dx
y := p0.y
x := p0.x
loop if x == p1.x break else {
*self.indexptr(x, y) = color
if D > 0 {
y += yi
D += 2 * (dy - dx)
} else {
D += 2 * dy
}
x += 1
}
}
put_line_high := fn(self: Self, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
dx := @as(int, @bitcast(p1.x - p0.x))
dy := @as(int, @bitcast(p1.y - p0.y))
xi := 1
if dy < 0 {
xi = -1
dx = -dx
}
D := @as(int, 2) * dx - dy
x := p0.x
y := p0.y
loop if y == p1.y break else {
*self.indexptr(x, y) = color
if D > 0 {
x += xi
D += 2 * (dx - dy)
} else {
D += 2 * dx
}
y += 1
}
}
put_line := fn(self: Self, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
if math.abs(uint, p1.y - p0.y) < math.abs(uint, p1.x - p0.x) {
if p0.x > p1.x {
@inline(put_line_low, self, p1, p0, color)
} else {
@inline(put_line_low, self, p0, p1, color)
}
} else { } else {
D += 2 * dy if p0.y > p1.y {
} @inline(put_line_high, self, p1, p0, color)
x += 1 } else {
} @inline(put_line_high, self, p0, p1, color)
return }
}
put_line_high := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
dx := @as(int, @bitcast(p1.x - p0.x))
dy := @as(int, @bitcast(p1.y - p0.y))
xi := 1
if dy < 0 {
xi = -1
dx = -dx
}
D := @as(int, 2) * dx - dy
x := p0.x
y := p0.y
loop if y == p1.y break else {
*indexptr(surface, x, y) = color
if D > 0 {
x += xi
D += 2 * (dx - dy)
} else {
D += 2 * dx
}
y += 1
}
return
}
put_line := fn(surface: Surface, p0: Vec2(uint), p1: Vec2(uint), color: Color): void {
if math.abs(uint, p1.y - p0.y) < math.abs(uint, p1.x - p0.x) {
if p0.x > p1.x {
@inline(put_line_low, surface, p1, p0, color)
} else {
@inline(put_line_low, surface, p0, p1, color)
}
} else {
if p0.y > p1.y {
@inline(put_line_high, surface, p1, p0, color)
} else {
@inline(put_line_high, surface, p0, p1, color)
} }
} }
return
}
put_surface := fn(surface: Surface, top: Surface, pos: Vec2(uint), flip_v: bool): void { put_surface := fn(self: Self, top: Self, pos: Vec2(uint), flip_v: bool): void {
src_top_cursor := top.buf src_top_cursor := top.buf
src_bottom_cursor := top.buf + top.width * (top.height - 1) src_bottom_cursor := top.buf + top.width * (top.height - 1)
dst_top_idx := indexptr(surface, pos.x, pos.y) dst_top_idx := self.indexptr(pos.x, pos.y)
dst_bottom_idx := indexptr(surface, pos.x, pos.y + top.height - 1) dst_bottom_idx := self.indexptr(pos.x, pos.y + top.height - 1)
dst_increment := surface.width dst_increment := self.width
if flip_v { if flip_v {
dst_increment = -dst_increment dst_increment = -dst_increment
tmp := dst_top_idx tmp := dst_top_idx
dst_top_idx = dst_bottom_idx dst_top_idx = dst_bottom_idx
dst_bottom_idx = tmp dst_bottom_idx = tmp
}
rows_to_copy := top.height
loop if rows_to_copy <= 1 break else {
memory.copy(Color, src_top_cursor, dst_top_idx, top.width)
memory.copy(Color, src_bottom_cursor, dst_bottom_idx, top.width)
dst_top_idx += dst_increment
dst_bottom_idx -= dst_increment
src_top_cursor += top.width
src_bottom_cursor -= top.width
rows_to_copy -= 2
}
if rows_to_copy == 1 {
memory.copy(Color, src_top_cursor, dst_top_idx, top.width)
}
return
}
// peony-made
put_trirect := fn(surface: Surface, pos: Vec2(uint), size: Vec2(int), color0: Color, color1: Color): void {
step := Vec2(int).(1, 1)
if size.x < 0 {
step.x = -1
}
if size.y < 0 {
step.y /= @bitcast(size.x)
}
start_y := pos.y
target := pos + @bitcast(size)
loop if pos.x == target.x break else {
@inline(put_vline, surface, pos.x, pos.y, target.y, color0)
@inline(put_vline, surface, pos.x, pos.y, start_y, color1)
pos += @bitcast(step)
}
return
}
// peony-made
put_vline := fn(surface: Surface, x: uint, y0: uint, y1: uint, color: Color): void {
if y1 < y0 {
tmp := y0
y0 = y1
y1 = tmp
}
y := y0
loop if y == y1 break else {
*indexptr(surface, x, y) = color
y += 1
}
return
}
// peony-made
put_hline := fn(surface: Surface, y: uint, x0: uint, x1: uint, color: Color): void {
if x1 < x0 {
tmp := x0
x0 = x1
x1 = tmp
}
memory.set(Color, &color, indexptr(surface, x0, y), @bitcast(x1 - x0))
}
put_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): void {
x := 0
y := radius
error := @as(int, 3) - 2 * @intcast(radius)
loop if x > y break else {
put_pixel(surface, pos + .(x, y), color)
put_pixel(surface, pos + .(-x, y), color)
put_pixel(surface, pos + .(x, -y), color)
put_pixel(surface, pos + .(-x, -y), color)
put_pixel(surface, pos + .(y, x), color)
put_pixel(surface, pos + .(-y, x), color)
put_pixel(surface, pos + .(y, -x), color)
put_pixel(surface, pos + .(-y, -x), color)
if error < 0 {
error += 4 * @intcast(x) + 6
} else {
error += 4 * (@intcast(x) - @intcast(y)) + 10
y -= 1
}
x += 1
}
}
put_filled_circle := fn(surface: Surface, pos: Vec2(uint), radius: uint, color: Color): void {
x := 0
y := radius
error := @as(int, 3) - 2 * @intcast(radius)
loop if x > y break else {
put_hline(surface, pos.y + y, pos.x - x, pos.x + x, color)
put_hline(surface, pos.y - y, pos.x - x, pos.x + x, color)
if x != y {
put_hline(surface, pos.y + x, pos.x - y, pos.x + y, color)
put_hline(surface, pos.y - x, pos.x - y, pos.x + y, color)
} }
if error < 0 { rows_to_copy := top.height
error += 4 * @intcast(x) + 6
} else {
error += 4 * (@intcast(x) - @intcast(y)) + 10
y -= 1
}
x += 1
}
}
put_textured_circle := fn(surface: Surface, source: Surface, source_pos: Vec2(uint), pos: Vec2(uint), radius: uint): void { loop if rows_to_copy <= 1 break else {
x := 0 memory.copy(Color, src_top_cursor, dst_top_idx, top.width)
y := radius memory.copy(Color, src_bottom_cursor, dst_bottom_idx, top.width)
error := @as(int, 3) - 2 * @intcast(radius)
loop if x > y break else { dst_top_idx += dst_increment
memory.copy(Color, indexptr(source, source_pos.x - x, source_pos.y + y), indexptr(surface, pos.x - x, pos.y + y), 2 * x) dst_bottom_idx -= dst_increment
memory.copy(Color, indexptr(source, source_pos.x - x, source_pos.y - y), indexptr(surface, pos.x - x, pos.y - y), 2 * x) src_top_cursor += top.width
src_bottom_cursor -= top.width
if x != y { rows_to_copy -= 2
memory.copy(Color, indexptr(source, source_pos.x - y, source_pos.y + x), indexptr(surface, pos.x - y, pos.y + x), 2 * y)
memory.copy(Color, indexptr(source, source_pos.x - y, source_pos.y - x), indexptr(surface, pos.x - y, pos.y - x), 2 * y)
} }
if error < 0 { if rows_to_copy == 1 {
error += 4 * @intcast(x) + 6 memory.copy(Color, src_top_cursor, dst_top_idx, top.width)
} else {
error += 4 * (@intcast(x) - @intcast(y)) + 10
y -= 1
} }
x += 1
} }
return // peony-made
} put_trirect := fn(self: Self, pos: Vec2(uint), size: Vec2(int), color0: Color, color1: Color): void {
step := Vec2(int).(1, 1)
if size.x < 0 {
step.x = -1
}
if size.y < 0 {
step.y /= @bitcast(size.x)
}
utf8_len_table := [u8].(0, 0, 2, 3) start_y := pos.y
target := pos + @bitcast(size)
put_text := fn(surface: Surface, font: Font, pos: Vec2(uint), color: Color, str: ^u8): void { loop if pos.x == target.x break else {
cursor := Vec2(uint).(pos.x, pos.y) @inline(put_vline, self, pos.x, pos.y, target.y, color0)
@inline(put_vline, self, pos.x, pos.y, start_y, color1)
pos += @bitcast(step)
}
}
max_y := surface.height - font.height // peony-made
next_line_y := font.height + font.line_gap put_vline := fn(self: Self, x: uint, y0: uint, y1: uint, color: Color): void {
char_advance := font.width + font.char_gap if y1 < y0 {
surface_width := surface.width tmp := y0
y0 = y1
y1 = tmp
}
y := y0
loop if *str == 0 break else { loop if y == y1 break else {
if cursor.y > max_y break *self.indexptr(x, y) = color
y += 1
}
}
glyph_data := @as(^u8, idk) // peony-made
code_point := @as(uint, 0) put_hline := fn(self: Self, y: uint, x0: uint, x1: uint, color: Color): void {
if x1 < x0 {
tmp := x0
x0 = x1
x1 = tmp
}
memory.set(Color, &color, self.indexptr(x0, y), @bitcast(x1 - x0))
}
if (*str & 0x80) == 0 { put_circle := fn(self: Self, pos: Vec2(uint), radius: uint, color: Color): void {
if *str == 10 { x := 0
cursor.x = pos.x y := radius
cursor.y += next_line_y error := @as(int, 3) - 2 * @intcast(radius)
str += 1 loop if x > y break else {
continue self.put_pixel(pos + .(x, y), color)
self.put_pixel(pos + .(-x, y), color)
self.put_pixel(pos + .(x, -y), color)
self.put_pixel(pos + .(-x, -y), color)
self.put_pixel(pos + .(y, x), color)
self.put_pixel(pos + .(-y, x), color)
self.put_pixel(pos + .(y, -x), color)
self.put_pixel(pos + .(-y, -x), color)
if error < 0 {
error += 4 * @intcast(x) + 6
} else {
error += 4 * (@intcast(x) - @intcast(y)) + 10
y -= 1
}
x += 1
}
}
put_filled_circle := fn(self: Self, pos: Vec2(uint), radius: uint, color: Color): void {
x := 0
y := radius
error := @as(int, 3) - 2 * @intcast(radius)
loop if x > y break else {
self.put_hline(pos.y + y, pos.x - x, pos.x + x, color)
self.put_hline(pos.y - y, pos.x - x, pos.x + x, color)
if x != y {
self.put_hline(pos.y + x, pos.x - y, pos.x + y, color)
self.put_hline(pos.y - x, pos.x - y, pos.x + y, color)
} }
if font.unicode == null { if error < 0 {
if *str > font.num_glyphs { error += 4 * @intcast(x) + 6
} else {
error += 4 * (@intcast(x) - @intcast(y)) + 10
y -= 1
}
x += 1
}
}
put_textured_circle := fn(self: Self, source: Self, source_pos: Vec2(uint), pos: Vec2(uint), radius: uint): void {
x := 0
y := radius
error := @as(int, 3) - 2 * @intcast(radius)
loop if x > y break else {
memory.copy(Color, source.indexptr(source_pos.x - x, source_pos.y + y), self.indexptr(pos.x - x, pos.y + y), 2 * x)
memory.copy(Color, source.indexptr(source_pos.x - x, source_pos.y - y), self.indexptr(pos.x - x, pos.y - y), 2 * x)
if x != y {
memory.copy(Color, source.indexptr(source_pos.x - y, source_pos.y + x), self.indexptr(pos.x - y, pos.y + x), 2 * y)
memory.copy(Color, source.indexptr(source_pos.x - y, source_pos.y - x), self.indexptr(pos.x - y, pos.y - x), 2 * y)
}
if error < 0 {
error += 4 * @intcast(x) + 6
} else {
error += 4 * (@intcast(x) - @intcast(y)) + 10
y -= 1
}
x += 1
}
}
put_text := fn(self: Self, font: Font, pos: Vec2(uint), color: Color, str: ^u8): void {
cursor := Vec2(uint).(pos.x, pos.y)
max_y := self.height - font.height
next_line_y := font.height + font.line_gap
char_advance := font.width + font.char_gap
self_width := self.width
loop if *str == 0 break else {
if cursor.y > max_y break
glyph_data := @as(^u8, idk)
code_point := @as(uint, 0)
if (*str & 0x80) == 0 {
if *str == 10 {
cursor.x = pos.x
cursor.y += next_line_y
str += 1 str += 1
continue continue
} }
glyph_data = get_glyph(font, *str)
} else { if font.unicode == null {
if *str < UNC_TABLE_SIZE { if *str > font.num_glyphs {
glyph_index := *(font.unicode + *str)
if glyph_index == 0xFFFF {
str += 1 str += 1
continue continue
} }
glyph_data = font.data + glyph_index * font.bytes_per_glyph glyph_data = get_glyph(font, *str)
} else { } else {
if *str < UNC_TABLE_SIZE {
glyph_index := *(font.unicode + *str)
if glyph_index == 0xFFFF {
str += 1
continue
}
glyph_data = font.data + glyph_index * font.bytes_per_glyph
} else {
str += 1
continue
}
}
str += 1
} else if font.unicode != null {
first_byte := *str
num_bytes := @as(uint, 0)
num_bytes = utf8_len_table[first_byte >> 5 & 0x3]
if num_bytes == 0 {
str += 1 str += 1
continue continue
} }
}
str += 1
} else if font.unicode != null {
first_byte := *str
num_bytes := @as(uint, 0)
num_bytes = utf8_len_table[first_byte >> 5 & 0x3] code_point = first_byte & (0x7F >> num_bytes | 0x1F)
if num_bytes == 0 { valid_sequence := true
str += 1 bytes_processed := 1
continue
}
code_point = first_byte & (0x7F >> num_bytes | 0x1F) loop if bytes_processed >= num_bytes break else {
str += 1
valid_sequence := true if *str == 0 | (*str & 0xC0) != 0x80 {
bytes_processed := 1 valid_sequence = false
}
loop if bytes_processed >= num_bytes break else { if valid_sequence == false {
str += 1 break
if *str == 0 | (*str & 0xC0) != 0x80 { }
valid_sequence = false code_point = code_point << 6 | *str & 0x3F
bytes_processed += 1
} }
if valid_sequence == false { if valid_sequence == false {
break str += 1
continue
} }
code_point = code_point << 6 | *str & 0x3F
bytes_processed += 1
}
if valid_sequence == false {
str += 1 str += 1
continue
if code_point == 10 {
cursor.x = pos.x
cursor.y += next_line_y
continue
}
if code_point >= UNC_TABLE_SIZE {
continue
}
glyph_index := *(font.unicode + code_point)
if glyph_index == 0xFFFF {
continue
}
glyph_data = font.data + glyph_index * font.bytes_per_glyph
} }
str += 1 if cursor.x + font.width >= self_width {
if code_point == 10 {
cursor.x = pos.x cursor.x = pos.x
cursor.y += next_line_y cursor.y += next_line_y
continue
} }
if code_point >= UNC_TABLE_SIZE { dest := self.indexptr(cursor.x, cursor.y)
continue rows := font.height
}
glyph_index := *(font.unicode + code_point) loop if rows == 0 break else {
if glyph_index == 0xFFFF { byte := *glyph_data
continue pixel_dest := dest
} mask := @as(u8, 0x80)
glyph_data = font.data + glyph_index * font.bytes_per_glyph bits := font.width
}
if cursor.x + font.width >= surface_width { loop if bits == 0 break else {
cursor.x = pos.x if (byte & mask) != 0 {
cursor.y += next_line_y *pixel_dest = color
} }
pixel_dest += 1
dest := indexptr(surface, cursor.x, cursor.y) mask >>= 1
rows := font.height if mask == 0 & bits > 0 {
glyph_data += 1
loop if rows == 0 break else { byte = *glyph_data
byte := *glyph_data mask = 0x80
pixel_dest := dest }
mask := @as(u8, 0x80) bits -= 1
bits := font.width
loop if bits == 0 break else {
if (byte & mask) != 0 {
*pixel_dest = color
} }
pixel_dest += 1
mask >>= 1 if mask != 0x80 {
if mask == 0 & bits > 0 {
glyph_data += 1 glyph_data += 1
byte = *glyph_data
mask = 0x80
} }
bits -= 1 dest += self_width
rows -= 1
} }
if mask != 0x80 { cursor.x += char_advance
glyph_data += 1
}
dest += surface_width
rows -= 1
} }
cursor.x += char_advance
} }
return
} }

View file

@ -1,6 +1,6 @@
.{math: .{Vec2}, buffer, log, memory, string} := @use("../../stn/src/lib.hb"); .{math: .{Vec2}, buffer, log, memory, string} := @use("../../stn/src/lib.hb");
.{Channel, Window, send_header, send_message, await_channel, await_header, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb"); .{Channel, Window, send_header, send_message, await_channel, await_header, await_message, message, BUFFER_SERVER, BUFFER_CLIENT, WindowProps, WindowData} := @use("./lib.hb");
.{new_surface, Color} := @use("../../render/src/lib.hb") .{Surface, Color} := @use("../../render/src/lib.hb")
// ! in the future this should be safely handled // ! in the future this should be safely handled
channel := Channel.(0, 0) channel := Channel.(0, 0)
@ -26,7 +26,7 @@ new := fn(props: WindowProps): ?Window {
return null return null
} }
log.info("client: recv windowdata\0") log.info("client: recv windowdata\0")
surface := new_surface(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y) surface := Surface.new(windowdata.body.props.dimensions.x, windowdata.body.props.dimensions.y)
return .(windowdata.body, surface) return .(windowdata.body, surface)
} }

View file

@ -1,5 +1,5 @@
.{math, log, string, random, buffer, memory} := @use("stn"); .{math, log, string, random, buffer, memory} := @use("stn");
.{Color, Surface, new_surface, put_surface, sync, put_rect, put_filled_rect, text, put_text, clear, white, black} := @use("lib:render"); .{Color, Surface, text} := @use("lib:render");
.{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("lib:sunset_proto") .{Channel, Window, WindowProps, WindowData, MessageHeader, BUFFER_SERVER, BUFFER_CLIENT, message, permissions, recv_header, recv_message, send_message, send_header, await_message} := @use("lib:sunset_proto")
WindowServer := struct { WindowServer := struct {
@ -54,14 +54,14 @@ incoming := fn(): bool {
title_length := string.length(title) title_length := string.length(title)
deco_length := title_length * 10 deco_length := title_length * 10
// draw the window tab bar // draw the window tab bar
put_filled_rect(surface, .(0, 0), .(data.props.dimensions.x + DECO_WIDTH + deco_length, DECO_HEIGHT_TOP), DECO_COLOUR) surface.put_filled_rect(.(0, 0), .(data.props.dimensions.x + DECO_WIDTH + deco_length, DECO_HEIGHT_TOP), DECO_COLOUR)
// Draw the window tab // Draw the window tab
put_filled_rect(surface, .(0, 0), .(deco_length, DECO_HEIGHT_TOP - 1), DECO_COLOUR_DARKER) surface.put_filled_rect(.(0, 0), .(deco_length, DECO_HEIGHT_TOP - 1), DECO_COLOUR_DARKER)
// Draw the outside box // Draw the outside box
put_rect(surface, .(0, 0), data.props.dimensions + .(DECO_WIDTH - 1, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM - 1), DECO_COLOUR) surface.put_rect(.(0, 0), data.props.dimensions + .(DECO_WIDTH - 1, DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM - 1), DECO_COLOUR)
put_text(surface, server.font, .(2, 1), .(0, 0, 0, 255), data.props.title) surface.put_text(server.font, .(2, 1), .(0, 0, 0, 255), data.props.title)
} }
server.windows[server.window_count] = .(data, surface) server.windows[server.window_count] = .(data, surface)
server.window_count += 1 server.window_count += 1
@ -76,10 +76,7 @@ $DECO_COLOUR := Color.(100, 200, 255, 255)
$DECO_COLOUR_DARKER := Color.(89, 57, 89, 255) $DECO_COLOUR_DARKER := Color.(89, 57, 89, 255)
new_window_decorations := fn(dimensions: math.Vec2(uint)): Surface { new_window_decorations := fn(dimensions: math.Vec2(uint)): Surface {
return new_surface( return @inline(Surface.new, dimensions.x + DECO_WIDTH, dimensions.y + DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM)
dimensions.x + DECO_WIDTH,
dimensions.y + DECO_HEIGHT_TOP + DECO_HEIGHT_BOTTOM,
)
} }
// ! compositor code. this currently disallows tearing. // ! compositor code. this currently disallows tearing.
@ -106,8 +103,7 @@ collect_frames := fn(): void {
if ptr.header.kind != message.ack { if ptr.header.kind != message.ack {
return return
} }
put_surface( window.surface.put_surface(
window.surface,
Surface.( Surface.(
ptr.body, ptr.body,
window.data.props.dimensions.x, window.data.props.dimensions.x,
@ -129,7 +125,7 @@ render_clients := fn(screen: Surface): void {
i += 1 i += 1
continue continue
} }
put_surface(screen, window.surface, window.data.props.position, false) screen.put_surface(window.surface, window.data.props.position, false)
i += 1 i += 1
} }
} }

View file

@ -21,15 +21,15 @@ main := fn(): void {
} }
text_label := Label.new_label("kernel : akern 0.2.0\0", 300) text_label := Label.new_label("kernel : akern 0.2.0\0", 300)
text_label.set_color(sunset.server.DECO_COLOUR, render.black) text_label.set_color(sunset.server.DECO_COLOUR, render.BLACK)
text_label_2 := Label.new_label("os : ableos\0", 300) text_label_2 := Label.new_label("os : ableos\0", 300)
text_label_2.set_color(sunset.server.DECO_COLOUR, render.black) text_label_2.set_color(sunset.server.DECO_COLOUR, render.BLACK)
text_label_3 := Label.new_label("wm : sunset\0", 300) text_label_3 := Label.new_label("wm : sunset\0", 300)
text_label_3.set_color(sunset.server.DECO_COLOUR, render.black) text_label_3.set_color(sunset.server.DECO_COLOUR, render.BLACK)
loop { loop {
render.clear(window.surface, render.black) render.clear(window.surface, render.BLACK)
// render.put_surface(window.surface, image, .(image.width + x % window.data.props.dimensions.x, 40), false) // render.put_surface(window.surface, image, .(image.width + x % window.data.props.dimensions.x, 40), false)
pos := Vec2(uint).(1, 100) pos := Vec2(uint).(1, 100)

View file

@ -1,4 +1,4 @@
render := @use("../../../../libraries/render/src/lib.hb") render := @use("lib:render")
/* expected result: /* expected result:
the impostor travels left and loops around the screen */ the impostor travels left and loops around the screen */
@ -7,13 +7,13 @@ example := fn(): void {
screen := render.init(true) screen := render.init(true)
x := 0 x := 0
loop { loop {
render.put_rect(screen, .(200 - x, 80), .(430, 380), render.red) screen.clear(render.BLACK)
render.put_rect(screen, .(630 - x, 120), .(120, 300), render.red) screen.put_rect(.(200 - x, 80), .(430, 380), render.RED)
render.put_rect(screen, .(200 - x, 460), .(160, 270), render.red) screen.put_rect(.(630 - x, 120), .(120, 300), render.RED)
render.put_rect(screen, .(470 - x, 460), .(160, 270), render.red) screen.put_rect(.(200 - x, 460), .(160, 270), render.RED)
render.put_rect(screen, .(140 - x, 140), .(340, 250), render.cyan) screen.put_rect(.(470 - x, 460), .(160, 270), render.RED)
render.sync(screen) screen.put_rect(.(140 - x, 140), .(340, 250), render.CYAN)
render.clear(screen, render.black) screen.sync()
x += 1 x += 1
} }
return return

View file

@ -1,4 +1,4 @@
render := @use("../../../../libraries/render/src/lib.hb") render := @use("lib:render")
/* expected result: /* expected result:
the screen fades from cyan to green the screen fades from cyan to green
@ -7,12 +7,11 @@ render := @use("../../../../libraries/render/src/lib.hb")
example := fn(): void { example := fn(): void {
screen := render.init(true) screen := render.init(true)
color := render.light_cyan color := render.LIGHT_CYAN
n := @as(u8, 1) n := @as(u8, 1)
loop { loop {
// ! dead code elimination bug screen.clear(color)
render.clear(screen, color) screen.sync()
render.sync(screen)
if color.b == 255 | color.b == 0 { if color.b == 255 | color.b == 0 {
n = -n n = -n
} }

View file

@ -1,13 +1,13 @@
.{log, math, string} := @use("../../../../libraries/stn/src/lib.hb") .{log, math, string} := @use("stn")
render := @use("../../../../libraries/render/src/lib.hb") render := @use("lib:render")
/* expected result: /* expected result:
a cute qoi image and a cute bmp image */ a cute qoi image and a cute bmp image */
example := fn(): void { example := fn(): void {
screen := render.init(true) screen := render.init(true)
image_qoi := render.image.from(@bitcast(&@embed("../../../../assets/mini.qoi"))) image_qoi := render.image.from(@bitcast(&@embed("sysdata:assets/mini.qoi")))
image_bmp := render.image.from(@bitcast(&@embed("../../../../assets/mini.bmp"))) image_bmp := render.image.from(@bitcast(&@embed("sysdata:assets/mini.bmp")))
if image_qoi == null | image_bmp == null { if image_qoi == null | image_bmp == null {
log.error("failed to load images for whatever reason\0") log.error("failed to load images for whatever reason\0")
@ -16,10 +16,10 @@ example := fn(): void {
t := 0.0 t := 0.0
loop { loop {
render.clear(screen, render.black) screen.clear(render.BLACK)
render.put_surface(screen, image_bmp, .(@bitcast(@fti(math.cos(t) * 100.0)) + (screen.width - image_bmp.width * 3) / 2, (screen.height - image_bmp.height) / 2), false) screen.put_surface(image_bmp, .(@bitcast(@fti(math.cos(t) * 100.0)) + (screen.width - image_bmp.width * 3) / 2, (screen.height - image_bmp.height) / 2), false)
render.put_surface(screen, image_qoi, .((screen.width + image_qoi.width) / 2, @bitcast(@fti(math.sin(t) * 100.0)) + (screen.height - image_qoi.height) / 2), false) screen.put_surface(image_qoi, .((screen.width + image_qoi.width) / 2, @bitcast(@fti(math.sin(t) * 100.0)) + (screen.height - image_qoi.height) / 2), false)
render.sync(screen) screen.sync()
t += 0.02 t += 0.02
} }
return return

View file

@ -1,5 +1,5 @@
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math .{Vec2} := @use("stn:math")
render := @use("../../../../libraries/render/src/lib.hb") render := @use("lib:render")
/* expected result: /* expected result:
a 3d-looking set of blue lines a 3d-looking set of blue lines
@ -7,15 +7,15 @@ render := @use("../../../../libraries/render/src/lib.hb")
example := fn(): void { example := fn(): void {
screen := render.init(true) screen := render.init(true)
render.clear(screen, .(100, 50, 0, 255)) screen.clear(.(100, 50, 0, 255))
p0 := Vec2(uint).(0, 0) p0 := Vec2(uint).(0, 0)
p1 := Vec2(uint).(0, screen.height) p1 := Vec2(uint).(0, screen.height)
loop if p0.y >= screen.height break else { loop if p0.y >= screen.height break else {
render.put_line(screen, p0, p1, .(255, 180, 100, 255)) screen.put_line(p0, p1, .(255, 180, 100, 255))
render.put_line(screen, .(screen.width, screen.height) - p0, .(screen.width, screen.height) - p1, .(255, 180, 100, 255)) screen.put_line(.(screen.width, screen.height) - p0, .(screen.width, screen.height) - p1, .(255, 180, 100, 255))
p0.y += screen.height >> 6 p0.y += screen.height >> 6
p1.x += screen.width >> 6 p1.x += screen.width >> 6
} }
render.sync(screen) screen.sync()
return return
} }

View file

@ -46,22 +46,22 @@ sunset := @use("lib:sunset_proto");
.{log} := @use("stn") .{log} := @use("stn")
// full mandelbrot // full mandelbrot
$X_MIN := -2.0 // $X_MIN := -2.0
$X_MAX := 0.47 // $X_MAX := 0.47
$Y_MIN := -1.12 // $Y_MIN := -1.12
$Y_MAX := 1.12 // $Y_MAX := 1.12
// a minibrot // a minibrot
// $X_MIN := -0.94 $X_MIN := -0.94
// $X_MAX := -0.93 $X_MAX := -0.93
// $Y_MIN := 0.31 $Y_MIN := 0.31
// $Y_MAX := 0.306 $Y_MAX := 0.306
// if you use the minibrot this should be at least 100 to actually see the minibrot, // if you use the minibrot this should be at least 100 to actually see the minibrot,
// if you use the mandelbrot it looks best under 30 // if you use the mandelbrot it looks best under 30
$MAX_MAX_ITERATION := 10000 $MAX_MAX_ITERATION := 30000000
$USE_SUNSET := true $USE_SUNSET := false
$COLOUR_R := 200 $COLOUR_R := 200
$COLOUR_G := 100 $COLOUR_G := 100
@ -71,7 +71,7 @@ $COLOUR_B := 255
// $COLOUR_G := 255 // $COLOUR_G := 255
// $COLOUR_B := 255 // $COLOUR_B := 255
// $INTERIOR_COLOUR := render.white // $INTERIOR_COLOUR := render.WHITE
$INTERIOR_COLOUR := render.Color.{r: COLOUR_R, g: COLOUR_G, b: COLOUR_B, a: 255} $INTERIOR_COLOUR := render.Color.{r: COLOUR_R, g: COLOUR_G, b: COLOUR_B, a: 255}
example := fn(): void { example := fn(): void {
@ -88,7 +88,7 @@ example := fn(): void {
} else { } else {
screen = render.init(false) screen = render.init(false)
} }
render.clear(screen, INTERIOR_COLOUR) screen.clear(INTERIOR_COLOUR)
max_iteration := 0 max_iteration := 0
prev_max_iteration := 0 prev_max_iteration := 0
@ -138,13 +138,13 @@ example := fn(): void {
b: @intcast(@fti(smooth_value * COLOUR_B)), b: @intcast(@fti(smooth_value * COLOUR_B)),
a: 0, a: 0,
} }
render.put_pixel(screen, .(px, py), colour) screen.put_pixel(.(px, py), colour)
} }
// faster // faster
if iteration >= max_iteration { if iteration >= max_iteration {
px += 2 px += 2
} else if iteration < 5 { } else if iteration < 5 {
render.put_hline(screen, py, px, px + 5, .(0, 0, 0, 0)) screen.put_hline(py, px, px + 5, .(0, 0, 0, 0))
px += 5 px += 5
} else { } else {
px += 1 px += 1
@ -160,9 +160,4 @@ example := fn(): void {
_ = sunset.client.send_frame(window) _ = sunset.client.send_frame(window)
} }
} }
// if USE_SUNSET {
// loop {
// _ = sunset.client.send_frame(window)
// }
// }
} }

View file

@ -1,8 +1,8 @@
.{Vec2, sin, cos, PI} := @use("../../../../libraries/stn/src/lib.hb").math .{Vec2, sin, cos, PI} := @use("stn:math")
render := @use("../../../../libraries/render/src/lib.hb") render := @use("lib:render")
able_bmp := @embed("../../../../assets/able.bmp") able_bmp := @embed("sysdata:assets/able.bmp")
mini_bmp := @embed("../../../../assets/mini.bmp") mini_bmp := @embed("sysdata:assets/mini.bmp")
/* expected result: /* expected result:
two textured circles rotating two textured circles rotating
@ -22,12 +22,12 @@ example := fn(): void {
screen := render.init(true) screen := render.init(true)
loop { loop {
render.clear(screen, render.black) screen.clear(render.BLACK)
render.put_filled_circle(screen, .(screen.width / 2, screen.height / 2), 128, render.light_yellow) screen.put_filled_circle(.(screen.width / 2, screen.height / 2), 128, render.LIGHT_YELLOW)
render.put_circle(screen, .(screen.width / 2, screen.height / 2), 256, render.light_blue) screen.put_circle(.(screen.width / 2, screen.height / 2), 256, render.LIGHT_BLUE)
render.put_textured_circle(screen, able, .(able.width / 2, able.height / 2), .(screen.width / 2 + @intcast(@fti(sin(angle) * 256)), screen.height / 2 + @intcast(@fti(cos(angle) * 256))), able.width / 2 - 1) screen.put_textured_circle(able, .(able.width / 2, able.height / 2), .(screen.width / 2 + @intcast(@fti(sin(angle) * 256)), screen.height / 2 + @intcast(@fti(cos(angle) * 256))), able.width / 2 - 1)
render.put_textured_circle(screen, mini, .(mini.width / 2, mini.height / 2), .(screen.width / 2 + @intcast(@fti(sin(angle + PI) * 256)), screen.height / 2 + @intcast(@fti(cos(angle + PI) * 256))), mini.width / 2 - 1) screen.put_textured_circle(mini, .(mini.width / 2, mini.height / 2), .(screen.width / 2 + @intcast(@fti(sin(angle + PI) * 256)), screen.height / 2 + @intcast(@fti(cos(angle + PI) * 256))), mini.width / 2 - 1)
render.sync(screen) screen.sync()
angle += 0.01 angle += 0.01
} }

View file

@ -3,14 +3,14 @@ render := @use("../../../../libraries/render/src/lib.hb")
example := fn(): void { example := fn(): void {
screen := render.init(false) screen := render.init(false)
render.clear(screen, render.black) screen.clear(render.BLACK)
loop { loop {
x := random.range(uint, 0, screen.width) x := random.range(uint, 0, screen.width)
y := random.range(uint, 0, screen.height) y := random.range(uint, 0, screen.height)
r := random.range(u8, 0, 255) r := random.range(u8, 0, 255)
g := random.range(u8, 0, 75) g := random.range(u8, 0, 75)
b := random.range(u8, 0, 155) b := random.range(u8, 0, 155)
render.put_pixel(screen, .(x, y), .(b, g, r, 255)) screen.put_pixel(.(x, y), .(b, g, r, 255))
} }
return return
} }

View file

@ -1,6 +1,5 @@
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math; .{math: .{Vec2}, random} := @use("stn")
.{random} := @use("../../../../libraries/stn/src/lib.hb") render := @use("lib:render")
render := @use("../../../../libraries/render/src/lib.hb")
/* expected result: /* expected result:
a square that changes colour bounces around the screen */ a square that changes colour bounces around the screen */
@ -12,9 +11,9 @@ example := fn(): void {
pos := Vec2(uint).((screen.width - side) / 2, (screen.height - side) / 2) pos := Vec2(uint).((screen.width - side) / 2, (screen.height - side) / 2)
color := random.any(render.Color) color := random.any(render.Color)
loop { loop {
render.put_filled_rect(screen, pos, .(side, side), color) screen.put_filled_rect(pos, .(side, side), color)
render.sync(screen) screen.sync()
render.clear(screen, render.black) screen.clear(render.BLACK)
if pos.x == 0 | pos.x == screen.width - side { if pos.x == 0 | pos.x == screen.width - side {
vel.x = -vel.x vel.x = -vel.x

View file

@ -1,6 +1,5 @@
.{Vec2} := @use("../../../../libraries/stn/src/lib.hb").math; .{math: .{Vec2}, random} := @use("stn")
.{random} := @use("../../../../libraries/stn/src/lib.hb") render := @use("lib:render")
render := @use("../../../../libraries/render/src/lib.hb")
/* expected result: /* expected result:
bouncing gradient square inside coloured bouncing box inside black screen */ bouncing gradient square inside coloured bouncing box inside black screen */
@ -8,7 +7,7 @@ render := @use("../../../../libraries/render/src/lib.hb")
example := fn(): void { example := fn(): void {
screen := render.init(true) screen := render.init(true)
image := render.new_surface(screen.width / 3, screen.height / 3) image := render.Surface.new(screen.width / 3, screen.height / 3)
vel := Vec2(int).(-1, -1) vel := Vec2(int).(-1, -1)
pos := Vec2(uint).(100, 100) pos := Vec2(uint).(100, 100)
side := image.width / 8 side := image.width / 8
@ -17,14 +16,14 @@ example := fn(): void {
color := random.any(render.Color) color := random.any(render.Color)
target_color := random.any(render.Color) target_color := random.any(render.Color)
loop { loop {
render.clear(screen, render.black) screen.clear(render.BLACK)
render.put_filled_rect(image, pos_inner, .(side, side), color) image.put_filled_rect(pos_inner, .(side, side), color)
render.put_rect(image, pos_inner, .(side, side), render.black) image.put_rect(pos_inner, .(side, side), render.BLACK)
render.put_rect(image, .(0, 0), .(image.width - 1, image.height - 1), color) image.put_rect(.(0, 0), .(image.width - 1, image.height - 1), color)
render.put_surface(screen, image, pos, false) screen.put_surface(image, pos, false)
render.put_rect(image, pos_inner, .(side, side), color) image.put_rect(pos_inner, .(side, side), color)
render.sync(screen) screen.sync()
if pos_inner.x == 0 | pos_inner.x == image.width - side { if pos_inner.x == 0 | pos_inner.x == image.width - side {
vel_inner.x = -vel_inner.x vel_inner.x = -vel_inner.x

View file

@ -1,7 +1,5 @@
render := @use("../../../../libraries/render/src/lib.hb"); .{math: .{Vec2}, random} := @use("stn")
.{math, random} := @use("../../../../libraries/stn/src/lib.hb") render := @use("lib:render")
Vec2 := math.Vec2
/* expected result: /* expected result:
a grid of green lines scrolling from the left top corner to the right bottom one a grid of green lines scrolling from the left top corner to the right bottom one
with a "target" randomly apperaing in one of them and a "seeker" "catching" it */ with a "target" randomly apperaing in one of them and a "seeker" "catching" it */
@ -33,32 +31,32 @@ example := fn(): void {
seeker := Vec2(uint).(random.range(uint, 0, range.x), random.range(uint, 0, range.y)) seeker := Vec2(uint).(random.range(uint, 0, range.x), random.range(uint, 0, range.y))
loop { loop {
render.clear(screen, render.black) screen.clear(render.BLACK)
target_pixel_coord := target * .(@bitcast(cell_size), @bitcast(cell_size)) + .(scroll, scroll) target_pixel_coord := target * .(@bitcast(cell_size), @bitcast(cell_size)) + .(scroll, scroll)
render.put_trirect(screen, target_pixel_coord, .(@bitcast(cell_size), @bitcast(cell_size)), render.red, render.light_red) screen.put_trirect(target_pixel_coord, .(@bitcast(cell_size), @bitcast(cell_size)), render.RED, render.LIGHT_RED)
render.put_hline(screen, target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.light_red) screen.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x - octcell, target_pixel_coord.x - sevenoctcell, render.LIGHT_RED)
render.put_hline(screen, target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.light_red) screen.put_hline(target_pixel_coord.y + halfcell, target_pixel_coord.x + cell_size + octcell, target_pixel_coord.x + cell_size + sevenoctcell, render.LIGHT_RED)
render.put_vline(screen, target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.light_red) screen.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y - octcell, target_pixel_coord.y - sevenoctcell, render.LIGHT_RED)
render.put_vline(screen, target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.light_red) screen.put_vline(target_pixel_coord.x + halfcell, target_pixel_coord.y + cell_size + octcell, target_pixel_coord.y + cell_size + sevenoctcell, render.LIGHT_RED)
x := scroll x := scroll
loop if x > width break else { loop if x > width break else {
render.put_vline(screen, x, 0, height, .(0, 127, 0, 127)) screen.put_vline(x, 0, height, .(0, 127, 0, 127))
x += cell_size x += cell_size
} }
y := scroll y := scroll
loop if y > height break else { loop if y > height break else {
render.put_hline(screen, y, 0, width, .(0, 127, 0, 127)) screen.put_hline(y, 0, width, .(0, 127, 0, 127))
y += cell_size y += cell_size
} }
render.put_hline(screen, seeker.y * cell_size + halfcell + scroll, 0, width, render.blue) screen.put_hline(seeker.y * cell_size + halfcell + scroll, 0, width, render.BLUE)
render.put_vline(screen, seeker.x * cell_size + halfcell + scroll, 0, height, render.blue) screen.put_vline(seeker.x * cell_size + halfcell + scroll, 0, height, render.BLUE)
render.sync(screen) screen.sync()
if seeker.x < target.x { if seeker.x < target.x {
seeker.x += 1 seeker.x += 1

View file

@ -1,5 +1,5 @@
.{memory, log, string, math} := @use("../../../../libraries/stn/src/lib.hb") .{memory, log, string, math} := @use("stn")
render := @use("../../../../libraries/render/src/lib.hb") render := @use("lib:render")
/* expected result: pretty decent notepad app /* expected result: pretty decent notepad app
slightly jank slightly jank
@ -13,8 +13,8 @@ render := @use("../../../../libraries/render/src/lib.hb")
- shift key support - shift key support
*/ */
psf := @embed("../../../../assets/consolefonts/tamsyn/10x20r.psf") psf := @embed("sysdata:assets/consolefonts/tamsyn/10x20r.psf")
img := @embed("../../../../assets/wallpaper.qoi") img := @embed("sysdata:assets/wallpaper.qoi")
is_shift_pressed := false is_shift_pressed := false
is_ctrl_pressed := false is_ctrl_pressed := false
@ -28,7 +28,7 @@ $down_arrow := 0x50
example := fn(): void { example := fn(): void {
screen := render.init(true) screen := render.init(true)
window := render.new_surface(600, 300) window := render.Surface.new(600, 300)
font := render.text.font_from_psf2(@bitcast(&psf), false) font := render.text.font_from_psf2(@bitcast(&psf), false)
wallpaper := render.image.from(@bitcast(&img)) wallpaper := render.image.from(@bitcast(&img))
@ -137,16 +137,16 @@ handle_extended_key := fn(scancode: u8, cursor: ^u8, bottom: ^u8, font: render.t
padding := 3 * @sizeof(render.Color) padding := 3 * @sizeof(render.Color)
draw_window := fn(window: render.Surface, font: render.text.Font, buf: ^u8, cursor: ^u8): void { draw_window := fn(window: render.Surface, font: render.text.Font, buf: ^u8, cursor: ^u8): void {
render.clear(window, .(0x88, 0xF4, 0xFC, 0x0)) window.clear(.(0x88, 0xF4, 0xFC, 0x0))
line := font.height + padding - 1 line := font.height + padding - 1
render.put_rect(window, .(0, 0), .(window.width - 1, window.height - 1), render.black) window.put_rect(.(0, 0), .(window.width - 1, window.height - 1), render.BLACK)
loop if line >= window.height break else { loop if line >= window.height break else {
render.put_hline(window, line, padding, window.width - padding, render.yellow) window.put_hline(line, padding, window.width - padding, render.YELLOW)
line += font.height line += font.height
} }
render.put_text(window, font, .(padding, padding), render.black, buf) window.put_text(font, .(padding, padding), render.BLACK, buf)
cursor_offset := cursor - buf cursor_offset := cursor - buf
@ -168,13 +168,13 @@ draw_window := fn(window: render.Surface, font: render.text.Font, buf: ^u8, curs
i += 1 i += 1
} }
render.put_rect(window, .(x_pos, y_pos), .(1, font.height - 1), render.black) window.put_rect(.(x_pos, y_pos), .(1, font.height - 1), render.BLACK)
} }
draw_screen := fn(screen: render.Surface, window: render.Surface, wallpaper: render.Surface): void { draw_screen := fn(screen: render.Surface, window: render.Surface, wallpaper: render.Surface): void {
render.put_surface(screen, wallpaper, .(0, 0), false) screen.put_surface(wallpaper, .(0, 0), false)
render.put_surface(screen, window, .(100, 100), false) screen.put_surface(window, .(100, 100), false)
render.sync(screen) screen.sync()
} }
handle_char := fn(char: u8, cursor: ^u8, bottom: ^u8): ^u8 { handle_char := fn(char: u8, cursor: ^u8, bottom: ^u8): ^u8 {

View file

@ -1 +1 @@
.{example: main} := @use("./examples/mandelbrot.hb") .{example: main} := @use("./examples/amogus.hb")

View file

@ -18,7 +18,7 @@ main := fn(): int {
} }
screen := render.init(true) screen := render.init(true)
render.clear(screen, render.black) screen.clear(render.BLACK)
font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false)) font := @unwrap(render.text.font_from_psf2(@bitcast(&psf), false))
wallpaper := render.image.from(@bitcast(&img)) wallpaper := render.image.from(@bitcast(&img))
@ -31,7 +31,7 @@ main := fn(): int {
mouse_y := 100 mouse_y := 100
text_label := Label.new_label("\0", 1024) text_label := Label.new_label("\0", 1024)
text_label.set_color(sunset.server.DECO_COLOUR, render.black) text_label.set_color(sunset.server.DECO_COLOUR, render.BLACK)
loop { loop {
mouse_event := intouch.recieve_mouse_event() mouse_event := intouch.recieve_mouse_event()
@ -71,10 +71,10 @@ main := fn(): int {
} }
} }
{ {
render.clear(screen, render.black) screen.clear(render.BLACK)
render.put_surface(screen, wallpaper, .(0, 0), false) screen.put_surface(wallpaper, .(0, 0), false)
render.put_rect(screen, .(0, 0), .(screen.width - 1, screen.height - 1), sunset.server.DECO_COLOUR) screen.put_rect(.(0, 0), .(screen.width - 1, screen.height - 1), sunset.server.DECO_COLOUR)
} }
if sunset.server.incoming() { if sunset.server.incoming() {
@ -87,16 +87,16 @@ main := fn(): int {
omnibar_height := 21 omnibar_height := 21
pos := Vec2(uint).(1, screen.height - omnibar_height) pos := Vec2(uint).(1, screen.height - omnibar_height)
render_label_to_surface(screen, text_label, font, pos) render_label_to_surface(screen, text_label, font, pos)
render.put_rect(screen, .(0, screen.height - 21), .(screen.width - 1, 20), sunset.server.DECO_COLOUR) screen.put_rect(.(0, screen.height - 21), .(screen.width - 1, 20), sunset.server.DECO_COLOUR)
} }
// Mouse cursor // Mouse cursor
{ {
render.put_filled_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER) screen.put_filled_circle(.(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR_DARKER)
render.put_circle(screen, .(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR) screen.put_circle(.(mouse_x, mouse_y), 10, sunset.server.DECO_COLOUR)
} }
render.sync(screen) screen.sync()
} }
return 0 return 0

View file

@ -25,11 +25,11 @@ resolution = "1024x768x24"
[boot.limine.ableos.modules.render_example] [boot.limine.ableos.modules.render_example]
path = "boot:///render_example.hbf" path = "boot:///render_example.hbf"
[boot.limine.ableos.modules.sunset_server] # [boot.limine.ableos.modules.sunset_server]
path = "boot:///sunset_server.hbf" # path = "boot:///sunset_server.hbf"
[boot.limine.ableos.modules.ps2_mouse_driver] # [boot.limine.ableos.modules.ps2_mouse_driver]
path = "boot:///ps2_mouse_driver.hbf" # path = "boot:///ps2_mouse_driver.hbf"
# [boot.limine.ableos.modules.ps2_keyboard_driver] # [boot.limine.ableos.modules.ps2_keyboard_driver]
# path = "boot:///ps2_keyboard_driver.hbf" # path = "boot:///ps2_keyboard_driver.hbf"