slifer 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/modules/graphics.ts +20 -5
- package/src/slifer.ts +32 -0
package/package.json
CHANGED
package/src/modules/graphics.ts
CHANGED
@@ -2,6 +2,7 @@ import { libimage, libsdl, libttf } from "../ffi";
|
|
2
2
|
import Global from "../global";
|
3
3
|
import { type Pointer, ptr } from 'bun:ffi';
|
4
4
|
import path from 'path';
|
5
|
+
import type { Rectangle, Vector2 } from "../slifer";
|
5
6
|
|
6
7
|
/** @internal */
|
7
8
|
class Graphics {
|
@@ -65,19 +66,33 @@ class Graphics {
|
|
65
66
|
* @param ys (optional) scale of y axis
|
66
67
|
* @param flip (optional) horizontal flip
|
67
68
|
*/
|
68
|
-
draw(image: Image,
|
69
|
+
draw(image: Image, position: Vector2, clipRectangle?: Rectangle, rotation?: number, xs?: number, ys?: number, flip?: true) {
|
69
70
|
const _dest = new Uint32Array(4);
|
70
71
|
const wArr = new Uint32Array(1);
|
71
72
|
const hArr = new Uint32Array(1);
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
let srcRect: null | Uint32Array = null;
|
74
|
+
|
75
|
+
if (clipRectangle == undefined) {
|
76
|
+
libsdl.symbols.SDL_QueryTexture((image as any).pointer, null, null, ptr(wArr), ptr(hArr));
|
77
|
+
} else {
|
78
|
+
srcRect = new Uint32Array(4);
|
79
|
+
srcRect[0] = clipRectangle.x;
|
80
|
+
srcRect[1] = clipRectangle.y;
|
81
|
+
srcRect[2] = clipRectangle.width;
|
82
|
+
srcRect[3] = clipRectangle.height;
|
83
|
+
wArr[0] = clipRectangle.width;
|
84
|
+
hArr[0] = clipRectangle.height;
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
_dest[0] = position.x;
|
89
|
+
_dest[1] = position.y;
|
75
90
|
_dest[2] = wArr[0] * (xs ? xs : 1);
|
76
91
|
_dest[3] = hArr[0] * (ys ? ys : 1);
|
77
92
|
const _center = new Uint32Array(2);
|
78
93
|
_center[0] = _dest[2] / 2;
|
79
94
|
_center[1] = _dest[3] / 2;
|
80
|
-
libsdl.symbols.SDL_RenderCopyEx(Global.ptrRenderer, (image as any).pointer,
|
95
|
+
libsdl.symbols.SDL_RenderCopyEx(Global.ptrRenderer, (image as any).pointer, srcRect, ptr(_dest), rotation ? rotation : 0, ptr(_center), flip ? Number(flip) : 0);
|
81
96
|
}
|
82
97
|
|
83
98
|
/**
|
package/src/slifer.ts
CHANGED
@@ -177,3 +177,35 @@ export class SliferClass {
|
|
177
177
|
return version;
|
178
178
|
}
|
179
179
|
}
|
180
|
+
|
181
|
+
export class Vector2 {
|
182
|
+
x;
|
183
|
+
y;
|
184
|
+
|
185
|
+
constructor(x: number, y: number) {
|
186
|
+
this.x = x;
|
187
|
+
this.y = y;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
export class Rectangle {
|
192
|
+
|
193
|
+
private readonly pointer;
|
194
|
+
readonly x;
|
195
|
+
readonly y;
|
196
|
+
readonly width;
|
197
|
+
readonly height;
|
198
|
+
|
199
|
+
constructor(x: number, y: number, width: number, height: number) {
|
200
|
+
const arr = new Uint32Array(4);
|
201
|
+
arr[0] = x;
|
202
|
+
arr[1] = y;
|
203
|
+
arr[2] = width;
|
204
|
+
arr[3] = height;
|
205
|
+
this.pointer = ptr(arr);
|
206
|
+
this.x = x;
|
207
|
+
this.y = y;
|
208
|
+
this.width = width;
|
209
|
+
this.height = height;
|
210
|
+
}
|
211
|
+
}
|