Pixel-Composer/scripts/__surface/__surface.gml

131 lines
2.7 KiB
Text
Raw Normal View History

2023-10-06 11:51:11 +02:00
function SurfaceAtlas(surface, _x = 0, _y = 0, rot = 0, sx = 1, sy = 1, blend = c_white, alpha = 1) constructor {
2023-04-16 15:26:52 +02:00
self.surface = new Surface(surface);
2023-10-06 11:51:11 +02:00
self.x = _x;
self.y = _y;
self.rotation = rot;
self.sx = sx;
self.sy = sy;
2023-04-16 15:26:52 +02:00
self.blend = blend;
self.alpha = alpha;
2023-10-06 11:51:11 +02:00
w = surface_get_width_safe(surface);
h = surface_get_height_safe(surface);
oriSurf = noone;
oriSurf_w = w;
oriSurf_h = h;
2023-11-28 06:50:54 +01:00
static set = function(surface, _x = 0, _y = 0, rot = 0, sx = 1, sy = 1, blend = c_white, alpha = 1) {
INLINE
self.surface = new Surface(surface);
self.x = _x;
self.y = _y;
self.rotation = rot;
self.sx = sx;
self.sy = sy;
self.blend = blend;
self.alpha = alpha;
w = surface_get_width_safe(surface);
h = surface_get_height_safe(surface);
return self;
}
2023-10-06 11:51:11 +02:00
static setOrginalSurface = function(surf) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
oriSurf = surf;
oriSurf_w = surface_get_width_safe(surf);
oriSurf_h = surface_get_height_safe(surf);
return self;
}
static getSurface = function() {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
return surface.get();
}
static setSurface = function(surface) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-07 09:09:18 +02:00
2023-10-06 11:51:11 +02:00
self.surface.set(surface);
w = surface_get_width_safe(surface);
h = surface_get_height_safe(surface);
}
2023-04-16 15:26:52 +02:00
static draw = function() {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
draw_surface_ext_safe(surface.get(), x, y, sx, sy, rotation, blend, alpha);
return self;
2023-04-16 15:26:52 +02:00
}
2023-10-10 07:12:42 +02:00
static clone = function(_surface = false) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
2023-10-10 07:12:42 +02:00
var _surf = getSurface();
if(_surface) _surf = surface_clone(_surf);
return new SurfaceAtlas(_surf, x, y, rotation, sx, sy, blend, alpha);
2023-04-16 15:26:52 +02:00
}
}
2023-03-21 03:01:53 +01:00
function Surface(surface) constructor {
static set = function(surface) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
2023-03-21 03:01:53 +01:00
self.surface = surface;
2023-09-08 21:37:36 +02:00
w = surface_get_width_safe(surface);
h = surface_get_height_safe(surface);
2023-03-21 03:01:53 +01:00
format = surface_get_format(surface);
}
set(surface);
2023-11-08 08:38:04 +01:00
static get = function() { INLINE return surface; }
2023-03-21 03:01:53 +01:00
2023-11-08 08:38:04 +01:00
static isValid = function() { INLINE return is_surface(surface); }
2023-03-21 03:01:53 +01:00
static resize = function(w, h) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
2023-03-21 03:01:53 +01:00
surface_resize(surface, w, h);
self.w = w;
self.h = h;
return self;
}
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
2023-10-06 11:51:11 +02:00
2023-03-21 03:01:53 +01:00
draw_surface_ext_safe(surface, x, y, xs, ys, rot, col, alpha);
return self;
}
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
2023-10-06 11:51:11 +02:00
2023-03-21 03:01:53 +01:00
draw_surface_stretched_ext(surface, x, y, w, h, col, alpha);
return self;
}
static destroy = function() {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
2023-03-21 03:01:53 +01:00
if(!isValid()) return;
surface_free(surface);
}
}
function Surface_get(surface) {
2023-11-08 08:38:04 +01:00
INLINE
2023-10-06 11:51:11 +02:00
2023-03-21 03:01:53 +01:00
if(is_real(surface))
return surface;
if(is_struct(surface) && struct_has(surface, "surface"))
return surface.surface;
return noone;
}