Pixel-Composer/scripts/dynaSurf/dynaSurf.gml

63 lines
1.9 KiB
Plaintext
Raw Normal View History

function dynaSurf() constructor {
2023-09-08 21:09:09 +02:00
surfaces = [];
2023-09-14 16:29:39 +02:00
static getAbsolutePos = function(_x, _y, _xs = 1, _ys = 1, _rot = 0) {
var _w = getWidth() * _xs;
var _h = getHeight() * _ys;
var _px = point_rotate(0, 0, _w / 2, _h / 2, _rot);
return [ _x - _px[0], _y - _px[1] ];
}
2023-09-09 13:52:16 +02:00
static getWidth = function() { return is_surface(surfaces[0])? surface_get_width(surfaces[0]) : 1; }
static getHeight = function() { return is_surface(surfaces[0])? surface_get_height(surfaces[0]) : 1; }
2023-09-08 21:09:09 +02:00
static draw = function(_x = 0, _y = 0, _sx = 1, _sy = 1, _ang = 0, _col = c_white, _alp = 1) {}
static drawStretch = function(_x = 0, _y = 0, _w = 1, _h = 1, _ang = 0, _col = c_white, _alp = 1) {
var _sx = _w / getWidth();
var _sy = _h / getHeight();
draw(_x, _y, _sx, _sy, _ang, _col, _alp);
}
static drawTile = function(_x = 0, _y = 0, _xs = 1, _ys = 1, _col = c_white, _alp = 1) {}
static drawPart = function(_l, _t, _w, _h, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alp = 1) {}
static onFree = function() {}
static free = function() {
for( var i = 0, n = array_length(surfaces); i < n; i++ )
surface_free_safe(surfaces[i]);
onFree();
}
static clone = function() {}
2023-09-11 16:08:58 +02:00
static destroy = function() {}
}
function compute_dynaSurf() : dynaSurf() constructor {
2023-09-11 16:08:58 +02:00
drawFn = noone;
widthFn = noone;
heightFn = noone;
2023-09-14 16:29:39 +02:00
useAbsolutePose = false;
2023-09-11 16:08:58 +02:00
static getWidth = function() { return widthFn? widthFn.eval() : 1; }
static getHeight = function() { return heightFn? heightFn.eval() : 1; }
static draw = function(_x = 0, _y = 0, _sx = 1, _sy = 1, _ang = 0, _col = c_white, _alp = 1) {
if(drawFn == noone) return;
2023-09-14 16:29:39 +02:00
var pos = useAbsolutePose? getAbsolutePos(_x, _y, _xs, _ys, _rot) : [ _x, _y ];
var params = {
2023-09-14 16:29:39 +02:00
x: pos[0],
y: pos[1],
2023-09-11 16:08:58 +02:00
sx: _sx,
sy: _sy,
angle: _ang,
color: _col,
alpha: _alp
};
drawFn.eval(params);
2023-09-11 16:08:58 +02:00
}
2023-09-08 21:09:09 +02:00
}