Skip to content

Commit

Permalink
Made Box<T> private.
Browse files Browse the repository at this point in the history
  • Loading branch information
smack0007 committed Sep 18, 2024
1 parent 0ba74a3 commit a97ebcd
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/renderer/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BoxArray, SDL } from "SDL_ts";
import { SDL } from "SDL_ts";
import { SDL_FUNCTIONS } from "./sdlConfig.ts";
import { ASSETS_PATH } from "../../shared/constants.ts";
import { join } from "@std/path";
Expand Down
30 changes: 12 additions & 18 deletions examples/same-game/fonts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BoxArray, int, Pointer, SDL, TTF } from "SDL_ts";
import { Pointer, SDL, TTF } from "SDL_ts";

const FONT_TEXTURE_SIZE = 256;

Expand All @@ -17,7 +17,7 @@ export type FontAtlas = {
export function createFontAtlas(
renderer: Pointer<SDL.Renderer>,
fontPath: string,
fontSize: number
fontSize: number,
): FontAtlas {
const fg = new SDL.Color(255, 255, 255, 255);
const bg = new SDL.Color(0, 0, 0, 0);
Expand All @@ -26,7 +26,7 @@ export function createFontAtlas(

if (font === null) {
throw new Error(
`Failed to open font in ${createFontAtlas.name}: ${SDL.GetError()}`
`Failed to open font in ${createFontAtlas.name}: ${SDL.GetError()}`,
);
}

Expand All @@ -35,21 +35,19 @@ export function createFontAtlas(
FONT_TEXTURE_SIZE,
FONT_TEXTURE_SIZE,
32,
SDL.PIXELFORMAT_RGBA8888
SDL.PIXELFORMAT_RGBA8888,
);

if (surface === null) {
throw new Error(
`Failed to create font surface in ${
createFontAtlas.name
}: ${SDL.GetError()}`
`Failed to create font surface in ${createFontAtlas.name}: ${SDL.GetError()}`,
);
}

SDL.FillRect(
surface,
null,
SDL.MapRGBA(surface.format, bg.r, bg.g, bg.b, bg.a)
SDL.MapRGBA(surface.format, bg.r, bg.g, bg.b, bg.a),
);

const glyphs: GlyphData[] = [];
Expand All @@ -62,13 +60,11 @@ export function createFontAtlas(

if (glyphSurface === null) {
throw new Error(
`Failed to create glyph surface in ${
createFontAtlas.name
}: ${SDL.GetError()}`
`Failed to create glyph surface in ${createFontAtlas.name}: ${SDL.GetError()}`,
);
}

const [ glyphWidth, glyphHeight ] = TTF.SizeUTF8(
const [glyphWidth, glyphHeight] = TTF.SizeUTF8(
font,
character,
);
Expand Down Expand Up @@ -99,7 +95,7 @@ export function createFontAtlas(

if (destination.y + destination.h >= FONT_TEXTURE_SIZE) {
throw new Error(
`Ran out of glyph space in font atlas in ${createFontAtlas.name}`
`Ran out of glyph space in font atlas in ${createFontAtlas.name}`,
);
}
}
Expand All @@ -119,9 +115,7 @@ export function createFontAtlas(

if (texture === null) {
throw new Error(
`Failed to create font texture in ${
createFontAtlas.name
}: ${SDL.GetError()}`
`Failed to create font texture in ${createFontAtlas.name}: ${SDL.GetError()}`,
);
}

Expand All @@ -141,7 +135,7 @@ export function drawString(
renderer: Pointer<SDL.Renderer>,
font: FontAtlas,
destination: SDL.Point,
text: string
text: string,
): void {
const destRect = new SDL.Rect(destination.x, destination.y, 0, 0);

Expand All @@ -163,7 +157,7 @@ export function drawString(

export function measureString(
font: FontAtlas,
text: string
text: string,
): { width: number; height: number } {
let width = 0;
let height = 0;
Expand Down
1 change: 0 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * as SDL from "./mod.SDL.ts";
export * as IMG from "./mod.SDL_image.ts";
export * as TTF from "./mod.SDL_ttf.ts";
export * from "./src/boxes.ts";
export * from "./src/error.ts";
export * from "./src/events.ts";
export * from "./src/memory.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/SDL/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getSymbolsFromFunctions } from "../_init.ts";
import { DynamicLibrary } from "../_library.ts";
import { symbols } from "./_symbols.ts";
import { PlatformPointer } from "../_types.ts";
import { Box } from "../boxes.ts";
import { Box } from "../_boxes.ts";
import { SDLError } from "../error.ts";
import { Pointer, PointerLike } from "../pointers.ts";
import { double, float, InitOptions, int, Uint16, Uint32, Uint64, Uint8 } from "../types.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/SDL_image/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getSymbolsFromFunctions } from "../_init.ts";
import { DynamicLibrary } from "../_library.ts";
import { symbols } from "./_symbols.ts";
import { PlatformPointer } from "../_types.ts";
import { Box } from "../boxes.ts";
import { Box } from "../_boxes.ts";
import { SDLError } from "../error.ts";
import { Pointer, PointerLike } from "../pointers.ts";
import { double, float, InitOptions, int, Uint16, Uint32, Uint64, Uint8 } from "../types.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/SDL_ttf/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getSymbolsFromFunctions } from "../_init.ts";
import { DynamicLibrary } from "../_library.ts";
import { symbols } from "./_symbols.ts";
import { PlatformPointer } from "../_types.ts";
import { Box } from "../boxes.ts";
import { Box } from "../_boxes.ts";
import { SDLError } from "../error.ts";
import { Pointer, PointerLike } from "../pointers.ts";
import { double, float, InitOptions, int, Uint16, Uint32, Uint64, Uint8 } from "../types.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/boxes.test.ts → src/_boxes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertEquals } from "@std/assert";
import { Box, BoxValueFactory } from "./boxes.ts";
import { Box, BoxValueFactory } from "./_boxes.ts";
import { Pointer } from "./pointers.ts";
import { double, float, int, Sint32, Uint16, Uint32, Uint8 } from "./types.ts";
import { PlatformDataView, PlatformPointer } from "./_types.ts";
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/pointers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isStruct } from "./_structs.ts";
import { isTypedArray } from "./_utils.ts";
import { Box, BoxArray, BoxValue } from "./boxes.ts";
import { Box, BoxArray, BoxValue } from "./_boxes.ts";
import { Struct, TypedArray } from "./types.ts";
import { PlatformPointer } from "./_types.ts";

Expand Down

0 comments on commit a97ebcd

Please sign in to comment.