Skip to content

Commit

Permalink
Added SetCallbackCacheUpdated and SetCallbackSurfaceUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
tabularelf committed Jun 27, 2024
1 parent ecabef9 commit 5162214
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions scripts/Canvas/Canvas.gml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function Canvas(_width, _height, _forceInit = false, _format = undefined) constr
__writeToCache = __CANVAS_AUTO_WRITE_TO_CACHE;
__index = -1;
__isAppSurf = false;
__CallBackCanvasCacheUpdated = undefined;
__CallbackCanvasSurfaceUpdated = undefined;

switch(__CANVAS_SURFACE_DEPTH_MODE) {
case 0: __depthDisabled = surface_get_depth_disable(); break;
Expand Down Expand Up @@ -49,6 +51,18 @@ function Canvas(_width, _height, _forceInit = false, _format = undefined) constr

#region Default Methods

/// @param {Function, Undefined} callback
static SetCallbackCacheUpdated = function(_callback) {
__CallBackCanvasCacheUpdated = _callback;
return self;
}

/// @param {Function, Undefined} callback
static SetCallbackUpdated = function(_callback) {
__CallbackCanvasSurfaceUpdated = _callback;
return self;
}

/// @param {Real} targetID use set_target_ext? (default: no) - any value != -1 will use set_target_ext
static Start = function(_targetID = -1) {
__index = _targetID;
Expand Down Expand Up @@ -83,6 +97,7 @@ function Canvas(_width, _height, _forceInit = false, _format = undefined) constr
}

__status = CanvasStatus.HAS_DATA;
__SurfaceUpdated();

return self;
}
Expand Down Expand Up @@ -177,6 +192,7 @@ function Canvas(_width, _height, _forceInit = false, _format = undefined) constr
}

__status = CanvasStatus.HAS_DATA;
__SurfaceUpdated();

return self;
}
Expand Down Expand Up @@ -222,6 +238,7 @@ function Canvas(_width, _height, _forceInit = false, _format = undefined) constr
}

__status = CanvasStatus.HAS_DATA;
__SurfaceUpdated();

return self;
}
Expand Down Expand Up @@ -436,6 +453,7 @@ function Canvas(_width, _height, _forceInit = false, _format = undefined) constr
__refContents.cbuff = __cacheBuffer;

buffer_seek(_cvBuff, buffer_seek_start, _oldTell);
__CacheUpdated();
return self;
}

Expand Down Expand Up @@ -900,9 +918,23 @@ function Canvas(_width, _height, _forceInit = false, _format = undefined) constr
}

static __UpdateCache = function() {
if (!surface_exists(__surface)) exit;
if (!surface_exists(__surface)) return;
buffer_get_surface(__buffer, __surface, 0);
__status = CanvasStatus.HAS_DATA;

__CacheUpdated();
}

static __SurfaceUpdated = function() {
if (__CallbackCanvasSurfaceUpdated != undefined) {
__CallbackCanvasSurfaceUpdated(self);
}
}

static __CacheUpdated = function() {
if (__CallBackCanvasCacheUpdated != undefined) {
__CallBackCanvasCacheUpdated(self);
}
}

static __ValidateContents = function() {
Expand All @@ -923,7 +955,7 @@ function Canvas(_width, _height, _forceInit = false, _format = undefined) constr
}
}

static __UpdateFormat = function(_format) {
static __UpdateFormat = function(_format) {
__format = _format ?? 0;
__bufferSize = 4;

Expand Down

0 comments on commit 5162214

Please sign in to comment.