Pixel-Composer/scripts/__surface/__surface.gml
2023-10-10 12:12:42 +07:00

113 lines
2.5 KiB
Plaintext

function SurfaceAtlas(surface, _x = 0, _y = 0, rot = 0, sx = 1, sy = 1, blend = c_white, alpha = 1) constructor {
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);
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");
self.surface.set(surface);
w = surface_get_width_safe(surface);
h = surface_get_height_safe(surface);
}
static draw = function() {
gml_pragma("forceinline");
draw_surface_ext_safe(surface.get(), x, y, sx, sy, rotation, blend, alpha);
return self;
}
static clone = function(_surface = false) {
gml_pragma("forceinline");
var _surf = getSurface();
if(_surface) _surf = surface_clone(_surf);
return new SurfaceAtlas(_surf, x, y, rotation, sx, sy, blend, alpha);
}
}
function Surface(surface) constructor {
static set = function(surface) {
gml_pragma("forceinline");
self.surface = surface;
w = surface_get_width_safe(surface);
h = surface_get_height_safe(surface);
format = surface_get_format(surface);
}
set(surface);
static get = function() { gml_pragma("forceinline"); return surface; }
static isValid = function() { gml_pragma("forceinline"); return is_surface(surface); }
static resize = function(w, h) {
gml_pragma("forceinline");
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) {
gml_pragma("forceinline");
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) {
gml_pragma("forceinline");
draw_surface_stretched_ext(surface, x, y, w, h, col, alpha);
return self;
}
static destroy = function() {
gml_pragma("forceinline");
if(!isValid()) return;
surface_free(surface);
}
}
function Surface_get(surface) {
gml_pragma("forceinline");
if(is_real(surface))
return surface;
if(is_struct(surface) && struct_has(surface, "surface"))
return surface.surface;
return noone;
}