Pixel-Composer/scripts/__surface/__surface.gml

113 lines
2.5 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;
static setOrginalSurface = function(surf) {
gml_pragma("forceinline");
oriSurf = surf;
oriSurf_w = surface_get_width_safe(surf);
oriSurf_h = surface_get_height_safe(surf);
return self;
}
static getSurface = function() {
gml_pragma("forceinline");
return surface.get();
}
static setSurface = function(surface) {
gml_pragma("forceinline");
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-10-06 11:51:11 +02:00
gml_pragma("forceinline");
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-10-06 11:51:11 +02:00
gml_pragma("forceinline");
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-10-06 11:51:11 +02:00
gml_pragma("forceinline");
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-10-06 11:51:11 +02:00
static get = function() { gml_pragma("forceinline"); return surface; }
2023-03-21 03:01:53 +01:00
2023-10-06 11:51:11 +02:00
static isValid = function() { gml_pragma("forceinline"); return is_surface(surface); }
2023-03-21 03:01:53 +01:00
static resize = function(w, h) {
2023-10-06 11:51:11 +02:00
gml_pragma("forceinline");
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-10-06 11:51:11 +02:00
gml_pragma("forceinline");
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-10-06 11:51:11 +02:00
gml_pragma("forceinline");
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-10-06 11:51:11 +02:00
gml_pragma("forceinline");
2023-03-21 03:01:53 +01:00
if(!isValid()) return;
surface_free(surface);
}
}
function Surface_get(surface) {
2023-10-06 11:51:11 +02:00
gml_pragma("forceinline");
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;
}