Jakt toolchain for TempleOS development
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
unholy-jakt/dc.jakt

143 lines
5.6 KiB

import extern c "dc.h" {
extern function dc_width(anon context: usize) -> i64
extern function dc_width_internal(anon context: usize) -> i64
extern function dc_height(anon context: usize) -> i64
extern function dc_buffer(anon context: usize) -> usize
extern function dc_color(anon context: usize) -> i64
extern function dc_thickness(anon context: usize) -> i64
extern function dc_alias(anon context: usize) -> usize
extern function dc_blot(destination: usize, x: i64, y: i64, source: usize)
extern function dc_copy(destination: usize, x: i64, y: i64, source: usize)
extern function dc_fill(anon context: usize, color: i64)
extern function dc_destroy(anon context)
extern function dc_draw_circle(anon context: usize, x: i64, y: i64, radius: i64)
extern function dc_draw_filled_rect(anon context: usize, x: i64, y: i64, width: i64, height: i64)
extern function dc_draw_line(anon context: usize, x1: i64, y1: i64, x2: i64, y2: i64)
extern function dc_draw_pixel(anon context: usize, x: i64, y: i64)
extern function dc_gr_dc() -> usize
extern function dc_new(width: i64, height: i64) -> usize
extern function dc_load_from_file(anon filename: raw c_char) -> usize
extern function dc_pixel_at(anon context: usize, x: i64, y: i64) -> i64
extern function dc_replace_color(anon context: usize, from: i64, to: i64)
extern function dc_save_to_file(anon filename: raw c_char, anon context: usize)
extern function dc_screenshot() -> usize
extern function dc_set_color(anon context: usize, color: i64)
extern function dc_set_thickness(anon context: usize, thickness: i64)
}
class DC {
public function width(this) -> i64 {
return dc_width(.context)
}
public function width_internal(this) -> i64 {
return dc_width_internal(.context)
}
public function height(this) -> i64 {
return dc_height(.context)
}
public function buffer(this) {
return dc_buffer(.context)
}
public function color(this) -> i64 {
return dc_color(.context)
}
public function thickness(this) -> i64 {
return dc_thickness(.context)
}
public context: usize
public function alias(this) throws -> DC {
return DC(context: dc_alias(.context))
}
public function blot(this, dc: DC, x: i64, y: i64) {
dc_blot(destination: dc.context, x, y, source: .context)
}
public function clear(this) {
.fill(color: 255)
}
public function copy(this, dc: DC, x: i64, y: i64) {
dc_copy(destination: dc.context, x, y, source: .context)
}
public function create_rect(width: i64, height: i64) throws -> DC {
mut dc = DC(context: 0);
dc.init(width, height)
return dc
}
public function fill(this, color: i64) {
dc_fill(.context, color)
}
function destroy(this) {
dc_destroy(.context)
}
public function flip_horizontal(mut this) throws {
mut flipped_dc = DC::create_rect(width: .width(), height: .height())
for y in 0..this.height() {
for x in 0..this.width() {
flipped_dc.set_color(.pixel_at(x: .width() - 1 - x, y))
flipped_dc.draw_pixel(x, y)
}
}
.destroy()
.context = flipped_dc.context
}
public function flip_vertical(mut this) throws {
mut flipped_dc = DC::create_rect(width: .width(), height: .height())
for y in 0..this.height() {
for x in 0..this.width() {
flipped_dc.set_color(.pixel_at(x, y: .height() - 1 - y))
flipped_dc.draw_pixel(x, y)
}
}
.destroy()
.context = flipped_dc.context
}
public function draw_circle(this, x: i64, y: i64, radius: i64) {
dc_draw_circle(.context, x, y, radius)
}
public function draw_filled_rect(this, x: i64, y: i64, width: i64, height: i64) {
dc_draw_filled_rect(.context x, y, width, height)
}
public function draw_line(this, x1: i64, y1: i64, x2: i64, y2: i64) {
dc_draw_line(.context, x1, y1, x2, y2)
}
public function draw_pixel(this, x: i64, y: i64) {
dc_draw_pixel(.context, x, y)
}
public function gr_dc() throws -> DC {
return DC(context: dc_gr_dc())
}
function init(mut this, width: i64, height: i64) {
.context = dc_new(width, height)
}
public function integer_scale(mut this, scale_factor: i64) throws {
mut scaled_dc = DC::create_rect(width: .width() * scale_factor, height: .height() * scale_factor)
for y in 0..this.height() {
for x in 0..this.width() {
scaled_dc.set_color(.pixel_at(x, y))
scaled_dc.draw_filled_rect(x: x * scale_factor, y: y * scale_factor, width: scale_factor, height: scale_factor)
}
}
.destroy()
.context = scaled_dc.context
}
public function load_from_file(anon filename: String) throws -> DC {
return DC(context: dc_load_from_file(filename.c_string()))
}
public function pixel_at(this, x: i64, y: i64) -> i64 {
return dc_pixel_at(.context, x, y)
}
public function replace_color(this, from: i64, to: i64) {
dc_replace_color(.context, from, to)
}
public function save_to_file(this, anon filename: String) {
dc_save_to_file(filename.c_string(), .context)
}
public function screenshot() throws -> DC {
return DC(context: dc_screenshot())
}
public function set_color(this, anon color: i64) {
dc_set_color(.context, color)
}
public function set_thickness(this, anon thickness: i64) {
dc_set_thickness(.context, thickness)
}
}