Pixel-Composer/scripts/panel_workspace/panel_workspace.gml

121 lines
3.2 KiB
Text
Raw Normal View History

2023-03-12 02:28:21 +01:00
function Panel_Workspace() : PanelContent() constructor {
workspaces = [];
w = ui(480);
2023-03-13 10:45:56 +01:00
h = ui(40);
scroll = 0;
scroll_to = 0;
scroll_max = 0;
hori = false;
2023-03-12 02:28:21 +01:00
2023-03-28 06:58:28 +02:00
layout_selecting = "";
2023-03-12 02:28:21 +01:00
function refreshContent() {
workspaces = [];
var f = file_find_first(DIRECTORY + "layouts/*", 0);
while(f != "") {
array_push(workspaces, filename_name_only(f));
f = file_find_next();
}
}
refreshContent();
2023-03-13 10:45:56 +01:00
function onFocusBegin() { refreshContent(); }
2023-03-12 02:28:21 +01:00
function drawContent(panel) {
draw_clear(COLORS.panel_bg_clear);
2023-03-13 10:45:56 +01:00
var _hori = hori;
hori = w > h;
if(hori != _hori) scroll_to = 0;
2023-03-12 02:28:21 +01:00
2023-03-13 10:45:56 +01:00
var x0 = hori? ui(6) + scroll : ui(6), x1;
var y0 = hori? ui(6) : ui(6) + scroll, y1;
var ww = 0;
var hh = 0;
2023-03-28 06:58:28 +02:00
var amo = array_length(workspaces);
2023-03-12 02:28:21 +01:00
draw_set_text(f_p1, hori? fa_left : fa_center, fa_top, COLORS._main_text_sub);
2023-03-28 06:58:28 +02:00
for( var i = 0; i <= amo; i++ ) {
var str = i == amo? "+" : workspaces[i];
var tw = hori? string_width(str) + ui(16) : w - ui(16);
var th = string_height(str) + ui(8);
2023-03-12 02:28:21 +01:00
x1 = x0 + tw;
y1 = y0 + th;
if(pHOVER && point_in_rectangle(mx, my, x0, y0, x1, y1)) {
draw_sprite_stretched(THEME.button_hide_fill, 1, x0, y0, x1 - x0, y1 - y0);
if(mouse_press(mb_left, pFOCUS)) {
2023-03-28 06:58:28 +02:00
if(i == amo) {
var dia = dialogCall(o_dialog_file_name, mouse_mx + ui(8), mouse_my + ui(8));
dia.name = PREF_MAP[? "panel_layout_file"];
dia.onModify = function(name) {
var cont = panelSerialize();
json_save_struct(DIRECTORY + "layouts/" + name + ".json", cont);
PREF_MAP[? "panel_layout_file"] = name;
PREF_SAVE();
refreshContent();
};
} else {
PREF_MAP[? "panel_layout_file"] = str;
PREF_SAVE();
setPanel();
}
}
if(mouse_press(mb_right, pFOCUS)) {
layout_selecting = str;
menuCall(,, [
menuItem("Select", function() {
PREF_MAP[? "panel_layout_file"] = layout_selecting;
PREF_SAVE();
setPanel();
}),
menuItem("Replace with current", function() {
var cont = panelSerialize();
json_save_struct(DIRECTORY + "layouts/" + layout_selecting + ".json", cont);
}),
menuItem("Delete", function() {
file_delete(DIRECTORY + "layouts/" + layout_selecting + ".json");
refreshContent();
}, THEME.cross),
]);
2023-03-12 02:28:21 +01:00
}
}
2023-03-28 06:58:28 +02:00
draw_set_color(PREF_MAP[? "panel_layout_file"] == str? COLORS._main_text : COLORS._main_text_sub)
draw_text_add(hori? x0 + ui(8) : (x0 + x1) / 2, y0 + ui(4), str);
2023-03-12 02:28:21 +01:00
2023-03-13 10:45:56 +01:00
if(hori) {
x0 += tw + ui(4);
ww += tw + ui(4);
} else {
y0 += th + ui(4);
hh += th + ui(4);
}
}
scroll = lerp_float(scroll, scroll_to, 5);
if(hori) {
scroll_max = max(ww - w + ui(16), 0);
if(pHOVER) {
2023-04-07 21:25:27 +02:00
if(mouse_wheel_down()) scroll_to = clamp(scroll_to - ui(128) * SCROLL_SPEED, -scroll_max, 0);
if(mouse_wheel_up()) scroll_to = clamp(scroll_to + ui(128) * SCROLL_SPEED, -scroll_max, 0);
2023-03-13 10:45:56 +01:00
}
} else {
scroll_max = max(hh - h + ui(16), 0);
if(pHOVER) {
2023-04-07 21:25:27 +02:00
if(mouse_wheel_down()) scroll_to = clamp(scroll_to - ui(32) * SCROLL_SPEED, -scroll_max, 0);
if(mouse_wheel_up()) scroll_to = clamp(scroll_to + ui(32) * SCROLL_SPEED, -scroll_max, 0);
2023-03-13 10:45:56 +01:00
}
2023-03-12 02:28:21 +01:00
}
}
}