Pixel-Composer/scripts/surfaceBox/surfaceBox.gml

117 lines
3.4 KiB
Text
Raw Normal View History

2023-01-17 08:11:55 +01:00
function surfaceBox(_onModify, def_path = "") : widget() constructor {
2022-09-27 06:37:28 +02:00
onModify = _onModify;
self.def_path = def_path;
open = false;
2023-01-17 08:11:55 +01:00
open_rx = 0;
open_ry = 0;
2022-09-27 06:37:28 +02:00
align = fa_center;
2023-10-06 11:51:11 +02:00
display_data = {};
cb_atlas_crop = new checkBox(function() {
display_data.atlas_crop = !display_data.atlas_crop;
display_data.update();
});
2022-09-27 06:37:28 +02:00
2023-01-17 08:11:55 +01:00
static trigger = function() {
open = true;
with(dialogCall(o_dialog_assetbox, x + w + open_rx, y + open_ry)) {
target = other;
gotoDir(other.def_path);
}
}
2023-10-06 11:51:11 +02:00
static setInteract = function(interactable) {
self.interactable = interactable;
cb_atlas_crop.interactable = true;
}
2023-07-30 19:56:53 +02:00
static drawParam = function(params) {
2023-10-06 11:51:11 +02:00
return draw(params.x, params.y, params.w, params.h, params.data, params.display_data, params.m, params.rx, params.ry);
2023-07-30 19:56:53 +02:00
}
2023-10-06 11:51:11 +02:00
static draw = function(_x, _y, _w, _h, _surface, _display_data, _m, _rx, _ry) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
open_rx = _rx;
open_ry = _ry;
2023-10-06 11:51:11 +02:00
display_data = _display_data;
2023-03-25 12:53:29 +01:00
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h);
2023-10-06 11:51:11 +02:00
var _type = VALUE_TYPE.surface;
var _surf_single = _surface;
if(is_array(_surf_single) && !array_empty(_surf_single))
_surf_single = _surf_single[0];
if(is_instanceof(_surf_single, dynaSurf)) {
_type = VALUE_TYPE.dynaSurface;
} else if(is_instanceof(_surf_single, SurfaceAtlas)) {
_type = VALUE_TYPE.atlas;
} else if(is_instanceof(_surf_single, __d3dMaterial)) {
_type = VALUE_TYPE.d3Material;
2023-10-06 11:51:11 +02:00
}
2023-03-25 12:53:29 +01:00
2022-09-27 06:37:28 +02:00
if(!open) {
2023-01-04 02:30:04 +01:00
draw_sprite_stretched(THEME.textbox, 3, _x, _y, _w, _h);
2023-10-06 11:51:11 +02:00
if(_type == VALUE_TYPE.surface && hover && hoverRect) {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.textbox, 1, _x, _y, _w, _h);
2023-01-17 08:11:55 +01:00
if(mouse_press(mb_left, active))
trigger();
2022-12-10 05:06:01 +01:00
if(mouse_click(mb_left, active))
2023-04-08 20:06:27 +02:00
draw_sprite_stretched_ext(THEME.textbox, 2, _x, _y, _w, _h, COLORS._main_accent, 1);
2022-09-27 06:37:28 +02:00
} else {
2023-01-17 08:11:55 +01:00
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, _h, c_white, 0.5 + 0.5 * interactable);
if(mouse_press(mb_left)) deactivate();
2022-09-27 06:37:28 +02:00
}
2022-11-03 11:44:49 +01:00
var pad = ui(12);
2022-09-27 06:37:28 +02:00
var sw = min(_w - pad, _h - pad);
var sh = sw;
var sx0 = _x + _w / 2 - sw / 2;
var sx1 = sx0 + sw;
var sy0 = _y + _h / 2 - sh / 2;
var sy1 = sy0 + sh;
2022-11-18 03:20:31 +01:00
draw_set_color(COLORS.widget_surface_frame);
2022-09-27 06:37:28 +02:00
draw_rectangle(sx0, sy0, sx1, sy1, true);
2023-02-19 02:13:19 +01:00
if(is_array(_surface) && array_length(_surface))
2023-02-20 10:16:31 +01:00
_surface = _surface[safe_mod(round(current_time / 250), array_length(_surface))];
if(is_instanceof(_surface, __d3dMaterial))
_surface = _surface.surface;
2022-09-27 06:37:28 +02:00
if(is_surface(_surface)) {
2023-09-08 21:37:36 +02:00
var sfw = surface_get_width_safe(_surface);
var sfh = surface_get_height_safe(_surface);
2022-09-27 06:37:28 +02:00
var ss = min(sw / sfw, sh / sfh);
2022-11-01 03:06:03 +01:00
var _sx = sx0 + sw / 2 - ss * sfw / 2;
var _sy = sy0 + sh / 2 - ss * sfh / 2;
2022-09-27 06:37:28 +02:00
2023-03-19 09:17:39 +01:00
draw_surface_ext_safe(_surface, _sx, _sy, ss, ss, 0, c_white, 1);
2022-09-27 06:37:28 +02:00
}
2023-10-06 11:51:11 +02:00
if(_type == VALUE_TYPE.surface)
draw_sprite_ui_uniform(THEME.scroll_box_arrow, 0, _x + _w - ui(20), _y + _h / 2, 1, COLORS._main_icon);
2022-09-27 06:37:28 +02:00
}
2023-01-17 08:11:55 +01:00
if(WIDGET_CURRENT == self)
2023-04-08 20:06:27 +02:00
draw_sprite_stretched_ext(THEME.widget_selecting, 0, _x - ui(3), _y - ui(3), _w + ui(6), _h + ui(6), COLORS._main_accent, 1);
2023-01-17 08:11:55 +01:00
2023-03-25 12:53:29 +01:00
if(DRAGGING && DRAGGING.type == "Asset" && hover && hoverRect) {
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, _x, _y, _w, _h, COLORS._main_value_positive, 1);
if(mouse_release(mb_left))
onModify(DRAGGING.data.path);
}
2023-01-17 08:11:55 +01:00
resetFocus();
2023-07-30 19:56:53 +02:00
return h;
2022-09-27 06:37:28 +02:00
}
}