Pixel-Composer/scripts/panel_preview_window/panel_preview_window.gml

159 lines
3.8 KiB
Plaintext
Raw Normal View History

2023-03-12 02:28:21 +01:00
function Panel_Preview_Window() : PanelContent() constructor {
min_w = ui(64);
min_h = ui(64);
padding = 8;
2023-03-23 13:38:50 +01:00
title_height = 24;
2023-03-12 02:28:21 +01:00
w = ui(200);
h = ui(200);
node_target = noone;
preview_channel = 0;
title_show = 0;
scale = 0;
2023-06-01 19:50:53 +02:00
scale_levels = [ 1/32, 1/24, 1/16, 1/12, 1/8, 1/4, 1/3, 1/2, 2/3, 1, 1.5, 2, 3, 4, 6, 8, 12, 16, 24, 32];
2023-03-12 02:28:21 +01:00
panx = 0;
pany = 0;
panning = false;
pan_mx = 0;
pan_my = 0;
pan_sx = 0;
pan_sy = 0;
2023-06-01 19:50:53 +02:00
2023-03-12 02:28:21 +01:00
function surfaceCheck() {
content_surface = surface_verify(content_surface, w, h);
}
function reset() {
scale = 0;
panx = 0;
pany = 0;
}
function changeChannel(index) {
var channel = index - array_length(menu);
for( var i = 0; i < ds_list_size(node_target.outputs); i++ ) {
var o = node_target.outputs[| i];
if(o.type != VALUE_TYPE.surface) continue;
if(channel-- == 0) {
preview_channel = i;
return;
}
}
}
content_surface = noone;
surfaceCheck();
menu = [
2023-06-04 18:28:29 +02:00
menuItem(__txtx("reset_view", "Reset view"), function() { reset(); }),
2023-03-12 02:28:21 +01:00
-1,
menuItem(__txt("Inspect"), function() { PANEL_GRAPH.nodes_selecting = [ node_target ]; }),
2023-06-04 18:28:29 +02:00
menuItem(__txtx("panel_graph_send_to_preview", "Send to preview"), function() { PANEL_PREVIEW.setNodePreview(node_target); }),
2023-03-12 02:28:21 +01:00
-1,
]
function drawContent(panel) {
if(node_target == noone) return;
title = node_target.getFullName();
surfaceCheck();
surface_set_target(content_surface);
draw_clear(COLORS.panel_bg_clear);
2023-06-13 14:42:06 +02:00
draw_sprite_tiled_ext(s_transparent, 0, 0, 0, 1, 1, COLORS.panel_preview_transparent, 1);
2023-03-12 02:28:21 +01:00
var surf = node_target.getPreviewValues();
surf = is_array(surf)? array_spread(surf) : [ surf ];
2023-03-12 02:28:21 +01:00
var dx = 0;
var dy = 0;
var ind = 0;
var col = round(sqrt(array_length(surf)));
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(surf); i < n; i++ ) {
2023-03-12 02:28:21 +01:00
var s = surf[i];
2023-09-08 21:37:36 +02:00
var sw = surface_get_width_safe(s);
var sh = surface_get_height_safe(s);
2023-03-12 02:28:21 +01:00
if(scale == 0)
2023-03-25 12:27:04 +01:00
scale = min(w / sw, h / sh);
var sx = dx + w / 2 - (sw * scale) / 2 + panx;
var sy = dy + h / 2 - (sh * scale) / 2 + pany;
2023-03-12 02:28:21 +01:00
2023-03-19 09:17:39 +01:00
draw_surface_ext_safe(s, sx, sy, scale, scale, 0, c_white, 1);
2023-03-12 02:28:21 +01:00
draw_set_color(COLORS._main_icon);
draw_rectangle(sx, sy, sx + sw * scale, sy + sh * scale, true);
if(++ind >= col) {
ind = 0;
dx = 0;
dy += (sh + 2) * scale;
} else
dx += (sw + 2) * scale;
}
surface_reset_target();
draw_surface_safe(content_surface);
2023-03-12 02:28:21 +01:00
if(panning) {
panx = pan_sx + (mouse_mx - pan_mx);
pany = pan_sy + (mouse_my - pan_my);
if(mouse_release(mb_middle))
panning = false;
}
if(mouse_press(mb_middle, pFOCUS)) {
panning = true;
pan_mx = mouse_mx;
pan_my = mouse_my;
pan_sx = panx;
pan_sy = pany;
}
if(pHOVER) {
var inc = 0.5;
2023-06-01 19:50:53 +02:00
if(scale > 64) inc = 4;
else if(scale > 16) inc = 2;
else if(scale > 8) inc = 1;
else if(scale > 2) inc = 0.5;
else if(scale > 0.25) inc = 0.25;
else inc = 0.05;
2023-03-12 02:28:21 +01:00
var s = scale;
2023-06-01 19:50:53 +02:00
if(mouse_wheel_down()) {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(scale_levels) - 1; i < n; i++ ) {
2023-06-01 19:50:53 +02:00
if(s > scale_levels[i] && s <= scale_levels[i + 1]) {
scale = scale_levels[i];
break;
}
}
}
if(mouse_wheel_up()) {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(scale_levels) - 1; i < n; i++ ) {
2023-06-01 19:50:53 +02:00
if(s >= scale_levels[i] && s < scale_levels[i + 1]) {
scale = scale_levels[i + 1];
break;
}
}
}
2023-03-12 02:28:21 +01:00
var ds = scale - s;
panx = panx / s * scale;
pany = pany / s * scale;
}
if(mouse_click(mb_right, pFOCUS)) {
var _menu = array_clone(menu);
for( var i = 0; i < ds_list_size(node_target.outputs); i++ ) {
var o = node_target.outputs[| i];
if(o.type != VALUE_TYPE.surface) continue;
array_push(_menu, menuItem(o.name, function(_dat) { changeChannel(_dat.index); }));
2023-03-12 02:28:21 +01:00
}
menuCall("preview_window_menu",,, _menu,, node_target);
2023-03-12 02:28:21 +01:00
}
}
}