Skip to content

Commit

Permalink
Fix Font render methods
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed Oct 2, 2024
1 parent 43edb2c commit 0f41fd8
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 34 deletions.
12 changes: 0 additions & 12 deletions client.ts

This file was deleted.

18 changes: 9 additions & 9 deletions examples/bouncy_rects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FPS } from "./utils.ts";
const window = new WindowBuilder("Hello, Deno!", 600, 800).build();
const canvas = window.canvas();

const boxes: any[] = [];
const boxes: { x: number; y: number; dx: number; dy: number }[] = [];
let num_boxes = 5;

function initBoxes() {
Expand Down Expand Up @@ -35,7 +35,7 @@ function checkCollision(
// 60 FPS cap
const stepFrame = FPS();

async function frame() {
function frame() {
canvas.setDrawColor(0, 0, 0, 255);
canvas.clear();
canvas.setDrawColor(255, 255, 255, 255);
Expand Down Expand Up @@ -77,20 +77,20 @@ async function frame() {
20,
)
) {
let dx = boxes[j].x - boxes[i].x;
let dy = boxes[j].y - boxes[i].y;
const dx = boxes[j].x - boxes[i].x;
const dy = boxes[j].y - boxes[i].y;
let d = Math.floor(Math.sqrt(dx * dx + dy * dy));

if (d === 0) {
d = 1;
}
let unitX = Math.floor(dx / d);
let unitY = Math.floor(dy / d);
const unitX = Math.floor(dx / d);
const unitY = Math.floor(dy / d);

let force = -2;
const force = -2;

let forceX = unitX * force;
let forceY = unitY * force;
const forceX = unitX * force;
const forceY = unitY * force;

boxes[i].dx += forceX;
boxes[i].dy += forceY;
Expand Down
2 changes: 1 addition & 1 deletion examples/font/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const surface = font.renderSolid(Deno.args[0] || "Hello there!", color);
const creator = canvas.textureCreator();
const texture = creator.createTextureFromSurface(surface);

async function frame() {
function frame() {
canvas.clear();
canvas.copy(texture);
canvas.present();
Expand Down
2 changes: 1 addition & 1 deletion examples/raw_window_handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventType, WindowBuilder } from "../mod.ts";
await navigator.gpu.requestAdapter();

const window = new WindowBuilder("Raw window handle", 640, 480).build();
const surface = window.windowSurface();
const _surface = window.windowSurface();

for await (const event of window.events()) {
if (event.type === EventType.Quit) break;
Expand Down
4 changes: 2 additions & 2 deletions examples/sprite/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ const self = createDenoInstance();
const shadow = createShadowInstance();

let cnt = 0;
let mouse = { x: 0, y: 0 };
const mouse = { x: 0, y: 0 };

function frame(e) {
function frame() {
canv.clear();
const tiles = drawMap(texture, canv, map, 16);

Expand Down
2 changes: 1 addition & 1 deletion examples/sprite/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Canvas, Rect, Texture } from "../../mod.ts";
import { type Canvas, Rect, type Texture } from "../../mod.ts";

export interface Area {
x: number;
Expand Down
2 changes: 1 addition & 1 deletion examples/stars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const cy = HEIGHT / 2;
const random = (u: number, l: number) => Math.random() * (u - l) + l;

for (let i = 0; i < star_count; i++) {
let star = [random(-25, 25), random(-25, 25), random(1, depth)];
const star = [random(-25, 25), random(-25, 25), random(1, depth)];
stars.push(star);
}

Expand Down
8 changes: 4 additions & 4 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,13 @@ export class Font {
* @param color the foreground color of the text
* @returns a Texture object
*/
renderSolid(text: string, color: Color): Texture {
renderSolid(text: string, color: Color): Surface {
const raw = sdl2Font.symbols.TTF_RenderText_Solid(
this[_raw],
asCString(text),
color[_raw],
);
return new Texture(raw);
return new Surface(raw);
}

/**
Expand All @@ -745,13 +745,13 @@ export class Font {
* @param color the foreground color of the text
* @returns a Texture object
*/
renderBlended(text: string, color: Color): Texture {
renderBlended(text: string, color: Color): Surface {
const raw = sdl2Font.symbols.TTF_RenderText_Blended(
this[_raw],
asCString(text),
color[_raw],
);
return new Texture(raw);
return new Surface(raw);
}
}

Expand Down
6 changes: 3 additions & 3 deletions webgpu-examples/boids/boids.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
Canvas,
type Canvas,
EventType,
PixelFormat,
Rect,
Texture,
type Texture,
TextureAccess,
Window,
type Window,
WindowBuilder,
} from "../../mod.ts";

Expand Down

0 comments on commit 0f41fd8

Please sign in to comment.