Pixel-Composer/scripts/__surface/__surface.gml

140 lines
3.5 KiB
Text
Raw Normal View History

2025-01-07 09:53:08 +01:00
function Atlas(_surface, _x = 0, _y = 0, _rot = 0, _sx = 1, _sy = 1, _blend = c_white, _alpha = 1) constructor {
surface = _surface;
x = _x;
y = _y;
rotation = _rot;
sx = _sx;
sy = _sy;
blend = _blend;
alpha = _alpha;
2024-01-24 06:19:34 +01:00
w = 1;
h = 1;
2025-01-07 09:53:08 +01:00
static getSurface = function() /*=>*/ {return surface};
static set = function(_surface, _x = 0, _y = 0, _rot = 0, _sx = 1, _sy = 1, _blend = c_white, _alpha = 1, setDim = true) {
2024-01-24 06:19:34 +01:00
INLINE
2025-01-07 09:53:08 +01:00
surface = _surface;
x = _x;
y = _y;
rotation = _rot;
sx = _sx;
sy = _sy;
blend = _blend;
alpha = _alpha;
2024-01-24 06:19:34 +01:00
return self;
}
2024-06-06 09:54:13 +02:00
static draw = function() {}
2024-01-24 06:19:34 +01:00
}
2025-01-07 09:53:08 +01:00
function SurfaceAtlasFast(_surface, _x = 0, _y = 0, _rot = 0, _sx = 1, _sy = 1, _blend = c_white, _alpha = 1) : Atlas(_surface, _x, _y, _rot, _sx, _sy, _blend, _alpha) constructor {}
function SurfaceAtlas( _surface, _x = 0, _y = 0, _rot = 0, _sx = 1, _sy = 1, _blend = c_white, _alpha = 1, setDim = true) : Atlas(_surface, _x, _y, _rot, _sx, _sy, _blend, _alpha) constructor {
surface = new Surface(_surface);
w = setDim? surface_get_width_safe(surface.surface) : 1;
h = setDim? surface_get_height_safe(surface.surface) : 1;
2023-10-06 11:51:11 +02:00
oriSurf = noone;
oriSurf_w = w;
oriSurf_h = h;
2025-01-07 09:53:08 +01:00
static getSurface = function() /*=>*/ {return surface.get()};
__base_set = set;
static set = function(_surface, _x = 0, _y = 0, _rot = 0, _sx = 1, _sy = 1, _blend = c_white, _alpha = 1, setDim = true) {
2023-11-28 06:50:54 +01:00
INLINE
2025-01-07 09:53:08 +01:00
__base_set(_surface, _x, _y, _rot, _sx, _sy, _blend, _alpha);
surface = new Surface(_surface);
2024-01-24 06:19:34 +01:00
2025-01-07 09:53:08 +01:00
w = setDim? surface_get_width_safe(surface.surface) : 1;
h = setDim? surface_get_height_safe(surface.surface) : 1;
2023-11-28 06:50:54 +01:00
return self;
}
2025-01-07 09:53:08 +01:00
static setOrginalSurface = function(_surface) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
2025-01-07 09:53:08 +01:00
oriSurf = _surface;
oriSurf_w = surface_get_width_safe(_surface);
oriSurf_h = surface_get_height_safe(_surface);
2023-10-06 11:51:11 +02:00
return self;
}
2025-01-07 09:53:08 +01:00
static setSurface = function(_surface) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
surface.set(_surface);
2025-01-07 09:53:08 +01:00
w = surface_get_width_safe(_surface);
h = surface_get_height_safe(_surface);
2023-10-06 11:51:11 +02:00
}
static draw = function(submitInt = false) {
var _surf = getSurface();
draw_surface_ext_safe(_surf, x, y, sx, sy, rotation, blend, alpha);
2023-10-06 11:51:11 +02:00
return self;
2023-04-16 15:26:52 +02:00
}
2025-01-07 09:53:08 +01:00
static clone = function(_cloneSurf = false) {
2023-10-10 07:12:42 +02:00
var _surf = getSurface();
2025-01-07 09:53:08 +01:00
if(_cloneSurf) _surf = surface_clone(_surf);
2023-10-10 07:12:42 +02:00
return new SurfaceAtlas(_surf, x, y, rotation, sx, sy, blend, alpha);
2023-04-16 15:26:52 +02:00
}
}
2025-01-07 09:53:08 +01:00
function Surface(_surf) constructor {
static set = function(_surf) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
2025-01-07 09:53:08 +01:00
self.surface = _surf;
w = surface_get_width_safe(_surf);
h = surface_get_height_safe(_surf);
format = surface_get_format(_surf);
2023-03-21 03:01:53 +01:00
}
2025-01-07 09:53:08 +01:00
set(_surf);
2023-03-21 03:01:53 +01:00
2025-01-07 09:53:08 +01:00
static get = function() /*=>*/ {return surface};
static isValid = function() /*=>*/ {return is_surface(surface)};
2023-03-21 03:01:53 +01:00
2025-01-07 09:53:08 +01:00
static resize = function(_w, _h) {
2023-11-08 08:38:04 +01:00
INLINE
2025-01-07 09:53:08 +01:00
surface_resize(surface, _w, _h);
w = _w; h = _h;
2023-03-21 03:01:53 +01:00
return self;
}
2025-01-07 09:53:08 +01:00
static draw = function(_x, _y, xs = 1, ys = 1, rot = 0, col = c_white, alpha = 1) {
2023-11-08 08:38:04 +01:00
INLINE
2025-01-07 09:53:08 +01:00
draw_surface_ext_safe(surface, _x, _y, xs, ys, rot, col, alpha);
2023-03-21 03:01:53 +01:00
return self;
}
2025-01-07 09:53:08 +01:00
static drawStretch = function(_x, _y, _w = 1, _h = 1, rot = 0, col = c_white, alpha = 1) {
2023-11-08 08:38:04 +01:00
INLINE
2025-01-07 09:53:08 +01:00
draw_surface_stretched_ext(surface, _x, _y, _w, _h, col, alpha);
2023-03-21 03:01:53 +01:00
return self;
}
static destroy = function() {
2023-11-08 08:38:04 +01:00
INLINE
2023-03-21 03:01:53 +01:00
if(!isValid()) return;
surface_free(surface);
}
}
2025-01-07 09:53:08 +01:00
function Surface_get(_surf) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
2025-01-07 09:53:08 +01:00
if(is_real(_surf))
return _surf;
if(is_struct(_surf) && struct_has(_surf, "surface"))
return _surf.surface;
2023-03-21 03:01:53 +01:00
return noone;
}