Flexible panel

This commit is contained in:
Tanasart 2023-03-11 12:40:34 +07:00
parent 73a735d5f0
commit 9155123dbe
16 changed files with 567 additions and 255 deletions

Binary file not shown.

View file

@ -1,29 +1,43 @@
{
"panel": {
"split": "h",
"width": -400,
"content": [
"split": "v",
"width": 40,
"content": [{
"content": "Panel_Menu"
},
{
"split": "v",
"width": -48,
"content": [
{
"split": "h",
"width": -400,
"content": [{
"split": "v",
"width": -400,
"content": [
{ "content": "PREVIEW" },
{ "content": "GRAPH" }
"width": -48,
"content": [{
"split": "v",
"width": -400,
"content": [{
"content": "Panel_Preview"
},
{
"content": "Panel_Graph"
}
]
},
{
"content": "Panel_Animation"
}
]
},
{ "content": "ANIMATION" }
{
"content": "Panel_Inspector"
}
]
},
{ "content": "INSPECTOR" }
}
]
},
"collection": {
"parent": "GRAPH",
"Panel_Collection": {
"parent": "Panel_Graph",
"width": 460,
"split": "h"
"split": "h",
"index": 0
}
}

View file

@ -1,29 +1,43 @@
{
"panel": {
"split": "h",
"width": -400,
"content": [
"split": "v",
"width": 40,
"content": [{
"content": "Panel_Menu"
},
{
"split": "v",
"width": -300,
"content": [
{
"split": "h",
"width": 400,
"content": [
{ "content": "PREVIEW" },
{ "content": "GRAPH" }
"split": "h",
"width": -400,
"content": [{
"split": "v",
"width": -300,
"content": [{
"split": "h",
"width": 400,
"content": [{
"content": "Panel_Preview"
},
{
"content": "Panel_Graph"
}
]
},
{
"content": "Panel_Animation"
}
]
},
{ "content": "ANIMATION" }
{
"content": "Panel_Inspector"
}
]
},
{ "content": "INSPECTOR" }
}
]
},
"collection": {
"parent": "ANIMATION",
"Panel_Collection": {
"parent": "Panel_Animation",
"width": 500,
"split": "h"
"split": "h",
"index": 0
}
}

View file

@ -54,7 +54,7 @@ event_inherited();
return;
PREF_MAP[? "display_scaling"] = PREF_MAP[? "_display_scaling"];
setPanel();
resetPanel();
loadFonts();
time_source_start(time_source_create(time_source_global, 1, time_source_units_frames, onResize));
@ -293,6 +293,15 @@ event_inherited();
PREF_MAP[? "connection_line_aa"] = max(1, real(str));
PREF_SAVE();
})
])
ds_list_add(pref_appr, [
get_text("panel_menu_right_control", "Use Windows style window control."),
"panel_menu_right_control",
new checkBox(function() {
PREF_MAP[? "panel_menu_right_control"] = !PREF_MAP[? "panel_menu_right_control"];
PREF_SAVE();
})
]);
#endregion

View file

@ -27,6 +27,7 @@
depth = 0;
win_wp = WIN_W;
win_hp = WIN_H;
win_resize = false;
room_width = WIN_W;
room_height = WIN_H;

View file

@ -24,7 +24,7 @@ if(OS == os_windows && gameframe_is_minimized()) {
#endregion
#region panels
if(PANEL_MAIN == 0) setPanel();
if(PANEL_MAIN == 0) resetPanel();
var surf = surface_get_target();
try

View file

@ -144,5 +144,9 @@
#endregion
//print("===== Step end =====");
if(keyboard_check_pressed(ord("Q")))
panelSerialize();
if(keyboard_check_pressed(ord("Q"))) {
if(key_mod_press(CTRL))
print(panelSerializeArray());
else
print(panelSerialize());
}

View file

@ -8,8 +8,12 @@
}
CURSOR = cr_default;
if(!gameframe_is_minimized() && (win_wp != WIN_W || win_hp != WIN_H) && (WIN_W > 1 && WIN_H > 1))
if(!gameframe_is_minimized() && (win_wp != WIN_W || win_hp != WIN_H) && (WIN_W > 1 && WIN_H > 1)) {
if(!win_resize) CURRENT_PANEL = panelSerialize();
display_refresh();
win_resize = true;
} else
win_resize = false;
#endregion
#region focus

View file

@ -7,7 +7,7 @@ function display_refresh() {
display_set_gui_size(WIN_SW, WIN_SH);
clearPanel();
setPanel();
resetPanel();
PANEL_GRAPH.fullView();
PANEL_PREVIEW.fullView();

View file

@ -77,6 +77,43 @@ function Panel_Animation() : PanelContent() constructor {
prev_cache = array_create(ANIMATOR.frames_total);
control_buttons = [
[ function() { return get_text("stop", "Stop"); },
function() { return 4; },
function() { return ANIMATOR.is_playing? COLORS._main_accent : COLORS._main_icon; },
function() {
ANIMATOR.is_playing = false;
ANIMATOR.setFrame(0);
} ],
[ function() { return ANIMATOR.is_playing? get_text("pause", "Pause") : get_text("play", "Play"); },
function() { return !ANIMATOR.is_playing; },
function() { return ANIMATOR.is_playing? COLORS._main_accent : COLORS._main_icon; },
function() {
ANIMATOR.is_playing = !ANIMATOR.is_playing;
ANIMATOR.frame_progress = true;
} ],
[ function() { return get_text("panel_animation_go_to_first_frame", "Go to first frame"); },
function() { return 3; },
function() { return COLORS._main_icon; },
function() { ANIMATOR.setFrame(0); }
],
[ function() { return get_text("panel_animation_go_to_last_frame", "Go to last frame"); },
function() { return 2; },
function() { return COLORS._main_icon; },
function() { ANIMATOR.setFrame(ANIMATOR.frames_total - 1); }
],
[ function() { return get_text("panel_animation_previous_frame", "Previous frame"); },
function() { return 5; },
function() { return COLORS._main_icon; },
function() { ANIMATOR.setFrame(ANIMATOR.real_frame - 1); }
],
[ function() { return get_text("panel_animation_next_frame", "Next frame"); },
function() { return 6; },
function() { return COLORS._main_icon; },
function() { ANIMATOR.setFrame(ANIMATOR.real_frame + 1); }
],
];
addHotkey("", "Play/Pause", vk_space, MOD_KEY.none, function() {
ANIMATOR.is_playing = !ANIMATOR.is_playing;
ANIMATOR.current_frame = -1;
@ -1359,45 +1396,64 @@ function Panel_Animation() : PanelContent() constructor {
function drawAnimationControl() {
var bx = ui(8);
if(w < ui(348))
bx = w / 2 - ui(36) * 6 / 2;
var by = h - ui(40);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, get_text("stop", "Stop"), THEME.sequence_control, 4, ANIMATOR.is_playing? COLORS._main_accent : COLORS._main_icon) == 2) {
ANIMATOR.is_playing = false;
ANIMATOR.setFrame(0);
if(w < ui(348)) {
bx = w / 2 - ui(36) * 6 / 2;
by = h - ui(40);
}
bx += ui(36);
var ind = !ANIMATOR.is_playing;
var cc = ANIMATOR.is_playing? COLORS._main_accent : COLORS._main_icon;
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, ANIMATOR.is_playing? get_text("pause", "Pause") : get_text("play", "Play"), THEME.sequence_control, ind, cc) == 2) {
ANIMATOR.is_playing = !ANIMATOR.is_playing;
ANIMATOR.frame_progress = true;
for( var i = 0; i < array_length(control_buttons); i++ ) {
var but = control_buttons[i];
var txt = but[0]();
var ind = but[1]();
var cc = but[2]();
var fnc = but[3];
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, txt, THEME.sequence_control, ind, cc) == 2)
fnc();
bx += ui(36);
}
bx += ui(36);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, get_text("panel_animation_go_to_first_frame", "Go to first frame"), THEME.sequence_control, 3) == 2) {
ANIMATOR.setFrame(0);
}
if(w < ui(348)) {
if(h < 72) return;
bx += ui(36);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, get_text("panel_animation_go_to_last_frame", "Go to last frame"), THEME.sequence_control, 2) == 2) {
ANIMATOR.setFrame(ANIMATOR.frames_total - 1);
}
var y0 = ui(8);
var y1 = h - ui(48);
var cy = (y0 + y1) / 2;
bx += ui(36);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, get_text("panel_animation_previous_frame", "Previous frame"), THEME.sequence_control, 5) == 2) {
ANIMATOR.setFrame(ANIMATOR.real_frame - 1);
}
draw_sprite_stretched(THEME.ui_panel_bg, 1, ui(8), y0, w - ui(16), y1 - y0);
bx += ui(36);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, get_text("panel_animation_next_frame", "Next frame"), THEME.sequence_control, 6) == 2) {
ANIMATOR.setFrame(ANIMATOR.real_frame + 1);
var pw = w - ui(16);
var px = ui(8) + pw * (ANIMATOR.current_frame / ANIMATOR.frames_total);
draw_set_color(COLORS._main_accent);
draw_line(px, y0, px, y1);
if(point_in_rectangle(mx, my, ui(8), y0, w - ui(16), y1)) {
if(mouse_click(mb_left, pFOCUS)) {
var rfrm = (mx - ui(8)) / (w - ui(16)) * ANIMATOR.frames_total;
ANIMATOR.setFrame(clamp(rfrm, 0, ANIMATOR.frames_total - 1));
}
}
var txt = string(ANIMATOR.current_frame + 1) + "/" + string(ANIMATOR.frames_total);
if(h < 100) {
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text_sub);
draw_text(ui(16), cy, "Frame");
draw_set_text(f_p1, fa_right, fa_center, ANIMATOR.is_playing? COLORS._main_accent : COLORS._main_text_sub);
draw_text(w - ui(16), cy, txt);
} else {
draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text_sub);
draw_text(w / 2, cy - ui(16), "Frame");
draw_set_text(f_h3, fa_center, fa_center, ANIMATOR.is_playing? COLORS._main_accent : COLORS._main_text_sub);
draw_text(w / 2, cy + ui(6), txt);
}
return;
}
if(w < ui(348)) return;
bx = w - ui(44);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, get_text("panel_animation_animation_settings", "Animation settings"), THEME.animation_setting, 2) == 2)
dialogCall(o_dialog_animation, x + bx + 32, y + by - 8);
@ -1420,7 +1476,7 @@ function Panel_Animation() : PanelContent() constructor {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
if(w < ui(348)) {
draw_sprite_stretched(THEME.ui_panel_bg, 1, ui(8), h - ui(32 + 8), w - ui(16), ui(32));
//
} else {
drawTimeline();
if(dope_sheet_h > 8)

View file

@ -19,7 +19,7 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
y = _y;
w = _w;
h = _h;
split = -1;
split = "";
min_w = ui(32);
min_h = ui(32);
@ -48,15 +48,8 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
}
function refresh() {
if(is_surface(content_surface) && surface_exists(content_surface))
surface_size_to(content_surface, w, h);
else
content_surface = surface_create_valid(w, h);
if(is_surface(mask_surface) && surface_exists(mask_surface))
surface_size_to(mask_surface, w, h);
else
mask_surface = surface_create_valid(w, h);
content_surface = surface_verify(content_surface, w, h);
mask_surface = surface_verify(mask_surface, w, h);
resetMask();
if(content != noone)
@ -98,23 +91,24 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
return true;
}
function refreshSize() { //refresh content surface after resize
function refreshSize(recur = true) { //refresh content surface after resize
//__debug_counter("refresh size");
if(content) {
content.w = w;
content.h = h;
content.onResize();
} else if(ds_list_size(childs) == 2) {
print("=== Refreshing (" + string(w) + ", " + string(h) + ") " + string(split) + " ===");
//print("=== Refreshing (" + string(w) + ", " + string(h) + ") " + string(split) + " ===");
var tw = childs[| 0].w + childs[| 1].w;
var th = childs[| 0].h + childs[| 1].h;
var fixChild = childs[| 1].x == x && childs[| 1].y == y;
var fixChild = split == "h"? childs[| 1].x < childs[| 0].x : childs[| 1].y < childs[| 0].y;
childs[| fixChild].x = x;
childs[| fixChild].y = y;
if(split == 0) {
if(split == "h") {
childs[| fixChild].w = childs[| fixChild].w / tw * w;
childs[| fixChild].h = h;
@ -123,7 +117,10 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
childs[| !fixChild].w = w - childs[| fixChild].w;
childs[| !fixChild].h = h;
} else if(split == 1) {
childs[| fixChild].anchor = ANCHOR.left;
childs[| !fixChild].anchor = ANCHOR.right;
} else if(split == "v") {
childs[| fixChild].w = w;
childs[| fixChild].h = childs[| fixChild].h / th * h;
@ -132,8 +129,12 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
childs[| !fixChild].w = w;
childs[| !fixChild].h = h - childs[| fixChild].h;
childs[| fixChild].anchor = ANCHOR.top;
childs[| !fixChild].anchor = ANCHOR.bottom;
}
if(recur)
for(var i = 0; i < ds_list_size(childs); i++) {
childs[| i].refreshSize();
}
@ -157,19 +158,7 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
w = max(w + dw, min_w);
h = max(h + dh, min_h);
if(w > 1 && h > 1) {
if(is_surface(content_surface))
surface_size_to(content_surface, w, h);
if(is_surface(mask_surface))
surface_size_to(mask_surface, w, h);
else
mask_surface = surface_create_valid(w, h);
resetMask();
}
refreshSize();
refreshSize(false);
}
function set(_content) {
@ -178,12 +167,15 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
}
function split_h(_w) {
if(abs(_w) > w) return noone;
if(abs(_w) > w) {
print("Error: Split panel larger than size w (" + string(_w) + " > " + string(w) + ")");
return noone;
}
if(_w < 0) _w = w + _w;
var _panelParent = new Panel(parent, x, y, w, h);
_panelParent.anchor = anchor;
_panelParent.split = 0;
_panelParent.split = "h";
var _panelL = self;
ds_list_add(_panelParent.childs, _panelL);
@ -211,12 +203,15 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
}
function split_v(_h) {
if(abs(_h) > h) return noone;
if(abs(_h) > h) {
print("Error: Split panel larger than size h (" + string(_h) + " > " + string(h) + ")");
return noone;
}
if(_h < 0) _h = h + _h;
var _panelParent = new Panel(parent, x, y, w, h);
_panelParent.anchor = anchor;
_panelParent.split = 1;
_panelParent.split = "v";
var _panelT = self;
ds_list_add(_panelParent.childs, _panelT);
@ -399,6 +394,9 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
break;
}
}
if(self == PANEL_MAIN && o_main.panel_dragging != noone && key_mod_press(CTRL))
checkHover();
}
function drawPanel() {
@ -415,7 +413,9 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
resetMask();
}
if(!is_surface(content_surface)) content_surface = surface_create_valid(w, h);
if(!is_surface(content_surface))
content_surface = surface_create_valid(w, h);
surface_set_target(content_surface);
draw_clear(COLORS.panel_bg_clear);
if(content) {
@ -442,58 +442,71 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
var ind = !ds_list_find_index(parent.childs, self); //index of the other child
var sib = parent.childs[| ind];
if(parent.childs[| ind].content == noone) { //other child is compound panel
if(sib.content == noone && ds_list_size(sib.childs) == 2) { //other child is compound panel
var gparent = parent.parent;
var pind = ds_list_find_index(gparent.childs, parent); //index of parent in grandparent object
gparent.childs[| pind] = sib;
gparent.refreshSize();
} else { //other child is content panel, set parent to content panel
if(gparent == noone) {
sib.x = PANEL_MAIN.x; sib.y = PANEL_MAIN.y;
sib.w = PANEL_MAIN.w; sib.h = PANEL_MAIN.h;
PANEL_MAIN = sib;
sib.parent = noone;
PANEL_MAIN.refreshSize();
} else {
var pind = ds_list_find_index(gparent.childs, parent); //index of parent in grandparent object
gparent.childs[| pind] = sib; //replace parent with sibling
sib.parent = gparent;
gparent.refreshSize();
}
} else if(sib.content != noone) { //other child is content panel, set parent to content panel
parent.set(sib.content);
ds_list_clear(parent.childs);
}
}
}
if(o_main.panel_dragging != noone && m_ot) {
var dx = (mouse_mx - x) / w;
var dy = (mouse_my - y) / h;
var p = ui(8);
if(o_main.panel_dragging != noone && m_ot && !key_mod_press(CTRL))
checkHover();
}
function checkHover() {
var dx = (mouse_mx - x) / w;
var dy = (mouse_my - y) / h;
var p = ui(8);
draw_set_color(COLORS._main_accent);
o_main.panel_hovering = self;
draw_set_color(COLORS._main_accent);
o_main.panel_hovering = self;
if(dx + dy > 1) {
if((1 - dx) + dy > 1) {
draw_set_alpha(.4);
draw_roundrect_ext(x + p, y + h / 2 + p, x + w - p, y + h - p, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(x + p, y + h / 2 + p, x + w - p, y + h - p, 8, 8, true);
if(dx + dy > 1) {
if((1 - dx) + dy > 1) {
draw_set_alpha(.4);
draw_roundrect_ext(x + p, y + h / 2 + p, x + w - p, y + h - p, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(x + p, y + h / 2 + p, x + w - p, y + h - p, 8, 8, true);
o_main.panel_split = 3;
} else {
draw_set_alpha(.4);
draw_roundrect_ext(x + p + w / 2, y + p, x + w - p, y + h - p, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(x + p + w / 2, y + p, x + w - p, y + h - p, 8, 8, true);
o_main.panel_split = 1;
}
o_main.panel_split = 3;
} else {
if((1 - dx) + dy > 1) {
draw_set_alpha(.4);
draw_roundrect_ext(x + p, y + p, x + w / 2 - p, y + h - p, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(x + p, y + p, x + w / 2 - p, y + h - p, 8, 8, true);
draw_set_alpha(.4);
draw_roundrect_ext(x + p + w / 2, y + p, x + w - p, y + h - p, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(x + p + w / 2, y + p, x + w - p, y + h - p, 8, 8, true);
o_main.panel_split = 2;
} else {
draw_set_alpha(.4);
draw_roundrect_ext(x + p, y + p, x + w - p, y + h / 2 - p, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(x + p, y + p, x + w - p, y + h / 2 - p, 8, 8, true);
o_main.panel_split = 1;
}
} else {
if((1 - dx) + dy > 1) {
draw_set_alpha(.4);
draw_roundrect_ext(x + p, y + p, x + w / 2 - p, y + h - p, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(x + p, y + p, x + w / 2 - p, y + h - p, 8, 8, true);
o_main.panel_split = 0;
}
o_main.panel_split = 2;
} else {
draw_set_alpha(.4);
draw_roundrect_ext(x + p, y + p, x + w - p, y + h / 2 - p, 8, 8, false);
draw_set_alpha(1.);
draw_roundrect_ext(x + p, y + p, x + w - p, y + h / 2 - p, 8, 8, true);
o_main.panel_split = 0;
}
}
}

View file

@ -38,66 +38,92 @@
}
function loadPanelStruct(panel, str) {
if(variable_struct_exists(str, "split")) {
if(variable_struct_exists(str, "split") && is_array(str.content)) {
var pan = panel;
if(str.split == "v")
pan = panel.split_v(ui(str.width));
else if(str.split == "h")
pan = panel.split_h(ui(str.width));
if(variable_struct_exists(str, "content")) {
if(pan != noone) {
loadPanelStruct(pan[0], str.content[0]);
loadPanelStruct(pan[1], str.content[1]);
}
} else if(variable_struct_exists(str, "content"))
} else {
panel.set(getPanelFromName(str.content));
}
}
function getPanelFromName(name) {
switch(name) {
case "INSPECTOR" : return PANEL_INSPECTOR;
case "ANIMATION" : return PANEL_ANIMATION;
case "PREVIEW" : return PANEL_PREVIEW;
case "GRAPH" : return PANEL_GRAPH;
case "Panel_Menu" : return PANEL_MENU;
case "Panel_Inspector" : return PANEL_INSPECTOR;
case "Panel_Animation" : return PANEL_ANIMATION;
case "Panel_Preview" : return PANEL_PREVIEW;
case "Panel_Graph" : return PANEL_GRAPH;
case "Panel_Collection" : return PANEL_COLLECTION;
}
return noone;
}
function loadPanel(path, panel) {
var f = json_load_struct(path);
loadPanelStruct(panel, f.panel);
CURRENT_PANEL = json_load_struct(path);
loadPanelStruct(panel, CURRENT_PANEL.panel);
}
function panelAdd(panel) {
var f = CURRENT_PANEL;
if(PREF_MAP[? "panel_collection"]) {
var pan = getPanelFromName(f.collection.parent);
if(struct_has(f, panel)) {
var str = f[$ panel];
var pan = getPanelFromName(str.parent);
var p;
if(f.collection.split == "v")
p = pan.panel.split_v(ui(f.collection.width));
else if(f.collection.split == "h")
p = pan.panel.split_h(ui(f.collection.width));
if(str.split == "v")
p = pan.panel.split_v(ui(str.width));
else if(str.split == "h")
p = pan.panel.split_h(ui(str.width));
p[0].set(PANEL_COLLECTION);
p[1].set(pan);
p[ str.index].set(PANEL_COLLECTION);
p[!str.index].set(pan);
}
}
function setPanel() {
PANEL_MAIN = new Panel(noone, ui(2), ui(2), WIN_SW - ui(4), WIN_SH - ui(4));
PANEL_MENU = new Panel_Menu();
PANEL_INSPECTOR = new Panel_Inspector();
PANEL_ANIMATION = new Panel_Animation();
PANEL_PREVIEW = new Panel_Preview();
PANEL_GRAPH = new Panel_Graph();
function panelObjectInit() {
PANEL_MAIN = new Panel(noone, ui(2), ui(2), WIN_SW - ui(4), WIN_SH - ui(4));
PANEL_MENU = new Panel_Menu();
PANEL_INSPECTOR = new Panel_Inspector();
PANEL_ANIMATION = new Panel_Animation();
PANEL_PREVIEW = new Panel_Preview();
PANEL_GRAPH = new Panel_Graph();
PANEL_COLLECTION = new Panel_Collection();
}
function resetPanel() {
clearPanel();
panelObjectInit();
loadPanelStruct(PANEL_MAIN, CURRENT_PANEL.panel);
var split_menu = PANEL_MAIN.split_v(ui(40));
split_menu[0].set(PANEL_MENU);
if(PREF_MAP[? "panel_collection"])
panelAdd("Panel_Collection");
PANEL_MAIN.refresh();
}
function setPanel() {
globalvar CURRENT_PANEL;
panelObjectInit();
zip_unzip("data/layouts.zip", DIRECTORY);
loadPanel(DIRECTORY + "layouts/" + PREF_MAP[? "panel_layout_file"] + ".json", split_menu[1]);
var file = DIRECTORY + "layouts/" + PREF_MAP[? "panel_layout_file"] + ".json";
if(!file_exists(file))
file = DIRECTORY + "layouts/Horizontal.json";
loadPanel(file, PANEL_MAIN);
if(PREF_MAP[? "panel_collection"])
panelAdd("Panel_Collection");
PANEL_ANIMATION.updatePropertyList();
PANEL_MAIN.refresh();
}
@ -129,24 +155,42 @@
function panelDraw() {
if(panel_dragging) {
draw_surface_ext(panel_dragging.dragSurface, mouse_mx + 8, mouse_my + 8, 0.5, 0.5, 0, c_white, 0.5);
if(mouse_release(mb_left)) {
var p = [];
var c = panel_hovering.content;
panel_hovering.content = noone;
switch(panel_split) {
case 0 : p = panel_hovering.split_v( panel_hovering.h / 2); break;
case 1 : p = panel_hovering.split_h( panel_hovering.w / 2); break;
case 2 : p = panel_hovering.split_h( panel_hovering.w / 2); break;
case 3 : p = panel_hovering.split_v( panel_hovering.h / 2); break;
if(panel_hovering == PANEL_MAIN) { //split main panel
var panel = new Panel(noone, ui(2), ui(2), WIN_SW - ui(4), WIN_SH - ui(4));
var main = PANEL_MAIN;
switch(panel_split) {
case 0 : p = panel.split_v( panel.h / 2); break;
case 1 : p = panel.split_h( panel.w / 2); break;
case 2 : p = panel.split_h( panel.w / 2); break;
case 3 : p = panel.split_v( panel.h / 2); break;
}
panel.parent.childs[| (panel_split + 1) % 2] = main;
main.parent = panel.parent;
panel.parent.childs[| (panel_split + 0) % 2].set(panel_dragging);
PANEL_MAIN.refreshSize();
} else {
var c = panel_hovering.content;
panel_hovering.content = noone;
switch(panel_split) {
case 0 : p = panel_hovering.split_v( panel_hovering.h / 2); break;
case 1 : p = panel_hovering.split_h( panel_hovering.w / 2); break;
case 2 : p = panel_hovering.split_h( panel_hovering.w / 2); break;
case 3 : p = panel_hovering.split_v( panel_hovering.h / 2); break;
}
p[(panel_split + 1) % 2].set(c);
p[(panel_split + 0) % 2].set(panel_dragging);
panel_hovering.refreshSize();
}
p[(panel_split + 1) % 2].set(c);
p[(panel_split + 0) % 2].set(panel_dragging);
panel_hovering.refreshSize();
panel_hovering = noone;
panel_dragging = noone;
}
@ -154,19 +198,48 @@
}
function panelSerialize() {
var cont = _panelSerialize(PANEL_MAIN);
print(json_stringify(cont, true));
var cont = {};
cont.panel = _panelSerialize(PANEL_MAIN);
return cont;
}
function _panelSerialize(panel) {
var cont = {};
var ind = 0;
cont.content = panel.content == noone? noone : instanceof(panel.content);
cont.split = panel.split;
if(panel.split != "" && ds_list_size(panel.childs) == 2) {
cont.split = panel.split;
if(panel.split == "h") {
ind = panel.childs[| 1].w < panel.childs[| 0].w;
cont.width = panel.childs[| ind].w * (panel.childs[| ind].x == panel.x? 1 : -1);
} else {
ind = panel.childs[| 1].h < panel.childs[| 0].h;
cont.width = panel.childs[| ind].h * (panel.childs[| ind].y == panel.y? 1 : -1);
}
cont.content = [];
ind = panel.childs[| 1].x == panel.x && panel.childs[| 1].y == panel.y;
for( var i = 0; i < ds_list_size(panel.childs); i++ )
cont.content[i] = _panelSerialize(panel.childs[| (ind + i) % 2]);
} else if(panel.content != noone)
cont.content = instanceof(panel.content);
cont.child = [];
for( var i = 0; i < ds_list_size(panel.childs); i++ )
cont.child[i] = _panelSerialize(panel.childs[| i]);
return cont;
}
function panelSerializeArray() {
return _panelSerializeArray(PANEL_MAIN);
}
function _panelSerializeArray(panel) {
var cont = [];
if(panel.content == noone) {
for( var i = 0; i < ds_list_size(panel.childs); i++ )
cont[i] = _panelSerializeArray(panel.childs[| i]);
} else
cont = instanceof(panel.content);
return cont;
}

View file

@ -1,5 +1,5 @@
function Panel_Menu() : PanelContent() constructor {
draggable = false;
draggable = true;
noti_flash = 0;
noti_flash_color = COLORS._main_accent;
@ -7,9 +7,9 @@ function Panel_Menu() : PanelContent() constructor {
noti_icon_show = 0;
noti_icon_time = 0;
if(OS == os_windows)
if(PREF_MAP[? "panel_menu_right_control"])
action_buttons = ["exit", "maximize", "minimize", "fullscreen"];
else if(OS == os_macosx)
else
action_buttons = ["exit", "minimize", "maximize", "fullscreen"];
menu_file = [
@ -148,6 +148,15 @@ function Panel_Menu() : PanelContent() constructor {
f = file_find_next();
}
array_push(arr, menuItem("Save layout", function() {
var dia = dialogCall(o_dialog_file_name, mouse_mx + ui(8), mouse_my + ui(8));
dia.onModify = function(name) {
var cont = panelSerialize();
json_save_struct(DIRECTORY + "layouts/" + name + ".json", cont);
};
}));
array_push(arr, -1);
for(var i = 0; i < array_length(lays); i++) {
array_push(arr, menuItem(lays[i],
function(_x, _y, _depth, _path) {
@ -161,9 +170,8 @@ function Panel_Menu() : PanelContent() constructor {
}).setIsShelf(),
-1,
menuItem(get_text("panel_menu_collections", "Collections"), function() {
clearPanel();
PREF_MAP[? "panel_collection"] = !PREF_MAP[? "panel_collection"];
setPanel();
resetPanel();
PREF_SAVE();
}),
menuItem(get_text("tunnels", "Tunnels"), function() {
@ -239,48 +247,90 @@ function Panel_Menu() : PanelContent() constructor {
function drawContent(panel) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
menus[6][1] = STEAM_ENABLED? menu_help_steam : menu_help;
var hori = w > h;
var xx = ui(40);
if(OS == os_windows)
xx = ui(24);
else if(OS == os_macosx) {
xx = ui(140);
draw_set_color(COLORS._main_icon_dark);
draw_line_round(xx, ui(8), xx, h - ui(8), 3);
var yy = ui(8);
if(hori) {
if(PREF_MAP[? "panel_menu_right_control"])
xx = ui(24);
else {
xx = ui(140);
draw_set_color(COLORS._main_icon_dark);
draw_line_round(xx, ui(8), xx, h - ui(8), 3);
}
var bx = xx;
if(!PREF_MAP[? "panel_menu_right_control"])
bx = w - ui(24);
draw_sprite_ui_uniform(THEME.icon_24, 0, bx, h / 2, 1, c_white);
if(pHOVER && point_in_rectangle(mx, my, bx - ui(16), 0, bx + ui(16), ui(32))) {
if(mouse_press(mb_left, pFOCUS))
dialogCall(o_dialog_about);
}
} else {
var bx = ui(20);
var by = h - ui(20);
draw_sprite_ui_uniform(THEME.icon_24, 0, bx, by, 1, c_white);
if(pHOVER && point_in_rectangle(mx, my, bx - ui(16), by - ui(16), bx + ui(16), by + ui(16))) {
if(mouse_press(mb_left, pFOCUS))
dialogCall(o_dialog_about);
}
}
var bx = xx;
if(OS == os_macosx)
bx = w - ui(24);
draw_sprite_ui_uniform(THEME.icon_24, 0, bx, h / 2, 1, c_white);
if(pHOVER && point_in_rectangle(mx, my, bx - ui(16), 0, bx + ui(16), ui(32))) {
if(mouse_press(mb_left, pFOCUS))
dialogCall(o_dialog_about);
if(hori) {
if(PREF_MAP[? "panel_menu_right_control"])
xx += ui(20);
else
xx += ui(8);
yy = 0;
} else {
xx = ui(8);
yy = w < ui(200)? ui(72) : ui(40);
}
if(OS == os_windows)
xx += ui(20);
else if(OS == os_macosx)
xx += ui(8);
var xc, x0, x1, yc, y0, y1;
for(var i = 0; i < array_length(menus); i++) {
draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text);
var ww = string_width(menus[i][0]) + ui(16);
var xc = xx + ww / 2;
var hh = line_height() + ui(8);
if(pHOVER && point_in_rectangle(mx, my, xc - ww / 2, 0, xc + ww / 2, h)) {
draw_sprite_stretched(THEME.menu_button, 0, xc - ww / 2, ui(6), ww, h - ui(12));
if(hori) {
xc = xx + ww / 2;
yc = h / 2;
x0 = xx;
x1 = xx + ww;
y0 = ui(6);
y1 = h - ui(6);
} else {
xc = w / 2;
yc = yy + hh / 2;
x0 = ui(6);
x1 = w - ui(6);
y0 = yy;
y1 = yy + hh;
}
if(pHOVER && point_in_rectangle(mx, my, x0, y0, x1, y1)) {
draw_sprite_stretched(THEME.menu_button, 0, x0, y0, x1 - x0, y1 - y0);
if((mouse_press(mb_left, pFOCUS)) || instance_exists(o_dialog_menubox)) {
menuCall( xx, h, menus[i][1]);
if(hori) menuCall( x + x0, y + y1, menus[i][1]);
else menuCall( x + x1, y + y0, menus[i][1]);
}
}
draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text);
draw_text_over(xx + ww / 2, h / 2, menus[i][0]);
draw_text_over(xc, yc, menus[i][0]);
xx += ww + 8;
if(hori) xx += ww + 8;
else yy += hh + 8;
}
#region notification
@ -292,8 +342,13 @@ function Panel_Menu() : PanelContent() constructor {
for( var i = 0; i < ds_list_size(ERRORS); i++ )
error_amo += ERRORS[| i].amount;
var nx0 = xx + ui(24);
var ny0 = h / 2;
if(hori) {
var nx0 = xx + ui(24);
var ny0 = h / 2;
} else {
var nx0 = ui(8);
var ny0 = yy + ui(16);
}
draw_set_text(f_p0, fa_left, fa_center);
var wr_w = ui(20) + ui(8) + string_width(string(warning_amo));
@ -305,7 +360,7 @@ function Panel_Menu() : PanelContent() constructor {
} else
noti_icon_show = lerp_float(noti_icon_show, 0, 4);
var nw = ui(16) + wr_w + ui(16) + er_w + noti_icon_show * ui(32);
var nw = hori? ui(16) + wr_w + ui(16) + er_w + noti_icon_show * ui(32) : w - ui(16);
var nh = ui(32);
noti_flash = lerp_linear(noti_flash, 0, 0.02);
@ -330,23 +385,25 @@ function Panel_Menu() : PanelContent() constructor {
if(noti_icon_show > 0)
draw_sprite_ui(noti_icon, 0, nx0 + nw - ui(16), ny0,,,,, noti_icon_show);
var wr_x = nx0 + ui(8);
var wr_x = hori? nx0 + ui(8) : w / 2 - (wr_w + er_w + ui(16)) / 2;
draw_sprite_ui_uniform(THEME.noti_icon_warning, warning_amo? 1 : 0, wr_x + ui(10), ny0);
draw_text(wr_x + ui(28), ny0, warning_amo);
var er_x = nx0 + ui(8) + wr_w + ui(16);
draw_sprite_ui_uniform(THEME.noti_icon_error, error_amo? 1 : 0, er_x + ui(10), ny0);
draw_text(er_x + ui(28), ny0, error_amo);
wr_x += wr_w + ui(16);
draw_sprite_ui_uniform(THEME.noti_icon_error, error_amo? 1 : 0, wr_x + ui(10), ny0);
draw_text(wr_x + ui(28), ny0, error_amo);
nx0 += nw + ui(8);
if(hori) nx0 += nw + ui(8);
else ny0 += nh + ui(8);
#endregion
#region addons
var wh = ui(32);
if(!hori) nx0 = ui(8);
with(addon) {
draw_set_text(f_p0, fa_center, fa_center, COLORS._main_text);
var ww = string_width(name) + ui(16);
var ww = hori? string_width(name) + ui(16) : w - ui(16);
if(other.pHOVER && point_in_rectangle(other.mx, other.my, nx0, ny0 - wh / 2, nx0 + ww, ny0 + wh / 2)) {
draw_sprite_stretched(THEME.menu_button, 1, nx0, ny0 - wh / 2, ww, wh);
@ -358,13 +415,16 @@ function Panel_Menu() : PanelContent() constructor {
draw_sprite_stretched(THEME.ui_panel_bg, 1, nx0, ny0 - wh / 2, ww, wh);
draw_text(nx0 + ww / 2, ny0, name);
nx0 += ww + ui(4);
if(hori) nx0 += ww + ui(4);
else ny0 += hh + ui(4);
}
#endregion
var x1 = w - ui(6);
if(OS == os_windows) x1 = w - ui(6);
else if(OS == os_macosx) x1 = ui(8 + 28);
if(PREF_MAP[? "panel_menu_right_control"])
x1 = w - ui(6);
else
x1 = ui(8 + 28);
#region actions
var bs = ui(28);
@ -427,26 +487,44 @@ function Panel_Menu() : PanelContent() constructor {
break;
}
if(OS == os_windows) x1 -= bs + ui(4);
else if(OS == os_macosx) x1 += bs + ui(4);
if(PREF_MAP[? "panel_menu_right_control"])
x1 -= bs + ui(4);
else
x1 += bs + ui(4);
}
#endregion
if(OS == os_macosx) x1 = w - ui(40);
if(!PREF_MAP[? "panel_menu_right_control"]) x1 = w - ui(40);
#region version
draw_set_text(f_p0, fa_right, fa_center, COLORS._main_text_sub);
var txt = "v. " + string(VERSION_STRING);
if(STEAM_ENABLED) txt += " Steam";
var ww = string_width(txt) + ui(12);
if(pHOVER && point_in_rectangle(mx, my, x1 - ww, 0, x1, h)) {
draw_sprite_stretched(THEME.button_hide_fill, 1, x1 - ww, ui(6), ww, h - ui(12));
if(mouse_press(mb_left, pFOCUS)) {
dialogCall(o_dialog_release_note);
if(hori) {
draw_set_text(f_p0, fa_right, fa_center, COLORS._main_text_sub);
var ww = string_width(txt) + ui(12);
if(pHOVER && point_in_rectangle(mx, my, x1 - ww, 0, x1, h)) {
draw_sprite_stretched(THEME.button_hide_fill, 1, x1 - ww, ui(6), ww, h - ui(12));
if(mouse_press(mb_left, pFOCUS)) {
dialogCall(o_dialog_release_note);
}
}
draw_text(x1 - ui(6), h / 2, txt);
} else {
var x1 = ui(40);
var y1 = h - ui(20);
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
var ww = string_width(txt) + ui(12);
if(pHOVER && point_in_rectangle(mx, my, x1, y1 - ui(16), x1 + ww, y1 + ui(16))) {
draw_sprite_stretched(THEME.button_hide_fill, 1, x1, y1 - ui(16), ww, ui(32));
if(mouse_press(mb_left, pFOCUS))
dialogCall(o_dialog_release_note);
}
draw_text(x1 + ui(6), y1, txt);
}
draw_text(x1 - ui(6), h / 2, txt);
#endregion
#region title
@ -460,16 +538,41 @@ function Panel_Menu() : PanelContent() constructor {
txt += " - Pixel Composer";
if(DEMO) txt += " DEMO";
var tx0 = nx0;
var tx1 = x1 - ww;
var maxW = abs(tx0 - tx1);
var tcx = (tx0 + tx1) / 2;
var tx0, tx1, maxW, tcx;
var ty0, ty1;
var tbx0, tby0;
if(hori) {
tx0 = nx0;
tx1 = x1 - ww;
ty0 = 0;
ty1 = h;
tcx = (tx0 + tx1) / 2;
} else {
tx0 = ui(8);
tx1 = w < ui(200)? w - ui(16) : w - ui(144);
ty0 = w < ui(200)? ui(36) : ui(6);
tcx = tx0;
}
maxW = abs(tx0 - tx1);
draw_set_font(f_p0b);
var tc = string_cut(txt, maxW);
var tw = string_width(tc) + ui(16);
var th = ui(28);
if(buttonInstant(THEME.button_hide_fill, tcx - tw / 2, h / 2 - ui(14), tw, ui(28), [mx, my], pFOCUS, pHOVER) == 2) {
if(hori) {
tbx0 = tcx - tw / 2;
tby0 = ty1 / 2 - ui(14);
} else {
tbx0 = tx0;
tby0 = ty0;
}
if(buttonInstant(THEME.button_hide_fill, tbx0, tby0, tw, th, [mx, my], pFOCUS, pHOVER) == 2) {
var arr = [];
var tip = [];
for(var i = 0; i < min(10, ds_list_size(RECENT_FILES)); i++) {
@ -479,12 +582,17 @@ function Panel_Menu() : PanelContent() constructor {
array_push(tip, [ method(_dat, _dat.getThumbnail), VALUE_TYPE.surface ]);
}
var dia = menuCall(tcx, h, arr, fa_center);
var dia = hori? menuCall(x + tcx, y + h, arr, fa_center) : menuCall(x + w, y + tby0, arr);
dia.tooltips = tip;
}
draw_set_text(f_p0b, fa_center, fa_center, COLORS._main_text_sub);
draw_text(tcx, h / 2, tc);
if(hori) {
draw_set_text(f_p0b, fa_center, fa_center, COLORS._main_text_sub);
draw_text(tcx, (ty0 + ty1) / 2, tc);
} else {
draw_set_text(f_p0b, fa_left, fa_center, COLORS._main_text_sub);
draw_text(tx0 + ui(8), tby0 + th / 2, tc);
}
#endregion
undoUpdate();

View file

@ -819,15 +819,14 @@ function Panel_Preview() : PanelContent() constructor {
}
}
function drawContent(panel) {
function drawContent(panel) {
mouse_on_preview = pHOVER && point_in_rectangle(mx, my, 0, toolbar_height, w, h - toolbar_height);
draw_clear(COLORS.panel_bg_clear);
if(canvas_bg == -1) {
if(canvas_s >= 1) draw_sprite_tiled_ext(s_transparent, 0, canvas_x, canvas_y, canvas_s, canvas_s, c_white, 0.5);
} else {
if(canvas_bg == -1 && canvas_s >= 1)
draw_sprite_tiled_ext(s_transparent, 0, canvas_x, canvas_y, canvas_s, canvas_s, c_white, 0.5);
else
draw_clear(canvas_bg);
}
dragCanvas();
getPreviewData();

View file

@ -64,6 +64,7 @@
PREF_MAP[? "dialog_add_node_h"] = 400;
PREF_MAP[? "panel_menu_resource_monitor"] = false;
PREF_MAP[? "panel_menu_right_control"] = os_type == os_windows;
#endregion
#region hotkeys

View file

@ -89,6 +89,22 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
var word = words[j];
if(j) word = " " + word;
if(string_width(word) > line_width) { //the entire word is longer than a line
for( var k = 1; k <= string_length(word); k++ ) {
var ch = string_char_at(word, k);
if(currW + string_width(ch) > line_width) {
array_push(_input_text_line, currL);
currW = 0;
currL = "";
}
currL += ch;
currW += string_width(ch);
}
continue;
}
if(currW + string_width(word) > line_width) {
array_push(_input_text_line, currL);
currW = 0;