file exploerer

This commit is contained in:
Tanasart 2024-05-16 20:28:45 +07:00
parent a01a979bb3
commit 2ff87ff393
37 changed files with 454 additions and 117 deletions

Binary file not shown.

View file

@ -3,7 +3,7 @@ event_inherited();
#region data
destroy_on_click_out = true;
dialog_w = ui(290);
dialog_w = ui(370);
dialog_h = ui(180);
paths = "";
@ -32,5 +32,6 @@ event_inherited();
ALL_NODES[? "Node_Image"],
ALL_NODES[? "Node_Image_Sequence"],
ALL_NODES[? "Node_Image_Animated"],
ALL_NODES[? "Node_Canvas"],
];
#endregion

View file

@ -22,8 +22,9 @@ if !ready exit;
var yy = dialog_y + ui(60);
PANEL_GRAPH.stepBegin();
var nx = PANEL_GRAPH.mouse_grid_x;
var ny = PANEL_GRAPH.mouse_grid_y;
var nx = (PANEL_GRAPH.w / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_x;
var ny = (PANEL_GRAPH.h / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_y;
draw_sprite_stretched(THEME.node_bg, 0, xx, yy, grid_size, grid_size);
if(sHOVER && point_in_rectangle(mouse_mx, mouse_my, xx, yy, xx + grid_width, yy + grid_size)) {
@ -40,6 +41,15 @@ if !ready exit;
}
break;
case "Node_Canvas" :
for( var i = 0, n = array_length(path_arr); i < n; i++ ) {
var path = path_arr[i];
var _canvas = nodeBuild("Node_Canvas", nx, ny);
_canvas.loadImagePath(path);
ny += 160;
}
break;
case "Node_Image_Sequence" : Node_create_Image_Sequence_path(nx, ny, path_arr); break;
case "Node_Image_Animated" : Node_create_Image_Animated_path(nx, ny, path_arr); break;
case "Node_Directory_Search" : Node_create_Directory_path(nx, ny, paths[0]); break;

View file

@ -106,7 +106,7 @@ event_inherited();
menuCall("palette_window_preset_menu",,, [
menuItem(__txtx("palette_editor_set_default", "Set as default"), function() {
DEF_PALETTE = array_clone(hovering.palette);
PROJECT.setPalette(array_clone(hovering.palette));
}),
menuItem(__txtx("palette_editor_delete", "Delete palette"), function() {
file_delete(hovering.path);

View file

@ -222,7 +222,7 @@ event_inherited();
menuCall("palette_window_preset_menu",,, [
menuItem(__txtx("palette_editor_set_default", "Set as default"), function() {
DEF_PALETTE = array_clone(hovering.palette);
PROJECT.setPalette(array_clone(hovering.palette));
}),
menuItem(__txtx("palette_editor_delete", "Delete palette"), function() {
file_delete(hovering.path);

View file

@ -11,7 +11,7 @@ event_inherited();
alarm[0] = -1;
menu = 1;
hght = ui(36);
hght = ui(32);
tooltips = [];
show_icon = false;

View file

@ -98,7 +98,7 @@ event_inherited();
menuCall("palette_window_preset_menu",,, [
menuItem(__txtx("palette_editor_set_default", "Set as default"), function() {
DEF_PALETTE = array_clone(hovering.palette);
PROJECT.setPalette(array_clone(hovering.palette));
}),
menuItem(__txtx("palette_editor_delete", "Delete palette"), function() {
file_delete(hovering.path);

View file

@ -231,7 +231,7 @@ if palette == 0 exit;
bx = content_x + ui(18);
if(buttonInstant(THEME.button_hide, bx, by, ui(28), ui(28), mouse_ui, interactable && sFOCUS, sHOVER, __txtx("palette_editor_load", "Load palette file") + " (.hex)", THEME.file) == 2) {
var path = get_open_filename("HEX palette|*.hex", "");
var path = get_open_filename_pxc("HEX palette|*.hex", "");
key_release();
if(isPaletteFile(path)) {

View file

@ -333,7 +333,7 @@ event_inherited();
__txtx("pref_ui_font", "Overwrite UI font") + "*",
"font_overwrite",
new textBox(TEXTBOX_INPUT.text, function(txt) { PREFERENCES.font_overwrite = txt; PREF_SAVE(); })
.setSideButton(button(function() { PREFERENCES.font_overwrite = get_open_filename("Font files (.ttf, .otf)|*.ttf;*.otf", ""); PREF_SAVE(); }, THEME.button_path_icon))
.setSideButton(button(function() { PREFERENCES.font_overwrite = get_open_filename_pxc("Font files (.ttf, .otf)|*.ttf;*.otf", ""); PREF_SAVE(); }, THEME.button_path_icon))
.setFont(f_p2)
.setEmpty()
));

View file

@ -132,10 +132,13 @@
drop_path = [];
function load_file_path(path) {
function load_file_path(path, _x = undefined, _y = undefined) {
if(!is_array(path)) path = [ path ];
if(array_length(path) == 0) return;
_x = _x == undefined? (PANEL_GRAPH.w / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_x : _x;
_y = _y == undefined? (PANEL_GRAPH.h / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_y : _y;
var type = "others";
if(array_length(path) == 1 && directory_exists(path[0]))
@ -169,36 +172,45 @@
switch(ext) {
case ".txt" :
node = Node_create_Text_File_Read_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p);
node = Node_create_Text_File_Read_path(_x, _y, p);
break;
case ".csv" :
node = Node_create_CSV_File_Read_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p);
node = Node_create_CSV_File_Read_path(_x, _y, p);
break;
case ".json" :
node = Node_create_Json_File_Read_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p);
node = Node_create_Json_File_Read_path(_x, _y, p);
break;
case ".ase" :
case ".aseprite" :
node = Node_create_ASE_File_Read_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p);
node = Node_create_ASE_File_Read_path(_x, _y, p);
break;
case ".png" :
case ".jpg" :
case ".jpeg" :
node = Node_create_Image_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p);
node = Node_create_Image_path(_x, _y, p);
break;
case ".gif" :
node = Node_create_Image_gif_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p);
node = Node_create_Image_gif_path(_x, _y, p);
break;
case ".obj" :
node = Node_create_3D_Obj_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p);
node = Node_create_3D_Obj_path(_x, _y, p);
break;
case ".wav" :
node = Node_create_WAV_File_Read_path(PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y, p);
node = Node_create_WAV_File_Read_path(_x, _y, p);
break;
case ".pxc" :
case ".cpxc" :
LOAD_PATH(p);
break;
case ".pxcc" :
APPEND(p);
break;

View file

@ -163,10 +163,10 @@ function draw_tooltip_sprite(spr) { #region
var sh = sprite_get_height(spr);
var sn = sprite_get_number(spr);
var ss = max(1, min(ui(64) / sw, ui(64) / sh));
var ss = min(max(1, min(ui(64) / sw, ui(64) / sh)), ui(320) / sw, ui(320) / sh);
var ww = sw * ss * sn + 2 * (sn - 1);
var hh = sh * ss;
var hh = sh * ss + ui(16);
var mx = min(mouse_mx + ui(16), WIN_W - (ww + ui(16)));
var my = min(mouse_my + ui(16), WIN_H - (hh + ui(16)));
@ -179,6 +179,9 @@ function draw_tooltip_sprite(spr) { #region
for( var i = 0; i < sn; i++ )
draw_sprite_ext(spr, i, sx + i * (sw * ss + 2), sy, ss, ss, 0, c_white, 1);
draw_set_text(f_p3, fa_center, fa_bottom, COLORS._main_text_sub);
draw_text(mx + (ww + ui(16)) / 2, my + hh + ui(16 - 4), $"{sw} x {sh} px");
} #endregion
function draw_tooltip_atlas(atlas) { #region

View file

@ -9,7 +9,7 @@ function __pack_file_strip(zip, path) {
function exportPortable(project = PROJECT) {
if(DEMO) return false;
var path = get_save_filename("Pixel Composer portable project (.zip)|*.zip", "");
var path = get_save_filename_pxc("Pixel Composer portable project (.zip)|*.zip", "");
key_release();
if(path == "") return false;

View file

@ -15,11 +15,11 @@ function filepath_resolve(path) { #region
return _path;
} #endregion
function get_open_filenames_compat(ext, sel) { #region
function get_open_filenames_compat(ext, sel, caption = "Open") { #region
INLINE
if(OS == os_windows) return get_open_filenames(ext, sel);
return get_open_filename(ext, sel);
if(OS == os_windows) return get_open_filenames_ext(ext, sel, PREFERENCES.dialog_path, caption);
return get_open_filename_pxc(ext, sel, caption);
} #endregion
function file_get_modify_s(path) { #region
@ -35,4 +35,20 @@ function file_get_modify_s(path) { #region
var _s = file_datetime_modified_second(path);
return ((((_y * 12 + _m) * 31 + _d) * 24 + _h) * 60 + _n) * 60 + _s;
} #endregion
} #endregion
function get_save_filename_pxc(filter, name, caption = "Save as") {
INLINE
var path = get_save_filename_ext(filter, name, PREFERENCES.dialog_path, caption);
if(path != "") PREFERENCES.dialog_path = filename_dir(path);
return path;
}
function get_open_filename_pxc(filter, name, caption = "Open") {
INLINE
var path = get_open_filename_ext(filter, name, PREFERENCES.dialog_path, caption);
if(path != "") PREFERENCES.dialog_path = filename_dir(path);
return path;
}

View file

@ -1,7 +1,7 @@
function LOAD(safe = false) { #region
if(DEMO) return false;
var path = get_open_filename("Pixel Composer project (.pxc)|*.pxc;*.cpxc", "");
var path = get_open_filename_pxc("Pixel Composer project (.pxc)|*.pxc;*.cpxc", "");
key_release();
if(path == "") return;
if(filename_ext(path) != ".json" && filename_ext(path) != ".pxc") return;
@ -172,8 +172,9 @@ function LOAD_AT(path, readonly = false, override = false) { #region
if(struct_has(_load_content, "graphGrid"))
struct_override(PROJECT.graphGrid, _load_content.graphGrid);
if(struct_has(_load_content, "attributes"))
if(struct_has(_load_content, "attributes")) {
struct_override(PROJECT.attributes, _load_content.attributes);
}
PROJECT.setPalette();
if(struct_has(_load_content, "notes")) {
@ -321,7 +322,7 @@ function LOAD_AT(path, readonly = false, override = false) { #region
} #endregion
function __IMPORT_ZIP() { #region
var path = get_open_filename("Pixel Composer portable project (.zip)|*.zip", "");
var path = get_open_filename_pxc("Pixel Composer portable project (.zip)|*.zip", "");
var _fname = filename_name_only(path);
var _fext = filename_ext(path);

View file

@ -1,7 +1,7 @@
function Node_create_3D_Obj(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("3d object|*.obj", "");
path = get_open_filename_pxc("3d object|*.obj", "");
key_release();
if(path == "") return noone;
}

View file

@ -1,7 +1,7 @@
function Node_create_ASE_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("Aseprite file (*.aseprite, *.ase)|*.aseprite;*.ase", "");
path = get_open_filename_pxc("Aseprite file (*.aseprite, *.ase)|*.aseprite;*.ase", "");
key_release();
if(path == "") return noone;
}

View file

@ -156,6 +156,9 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
temp_surface = array_create(1);
live_edit = false;
live_target = "";
input_display_list = [
["Output", false], 0, frame_renderer, 12, 13,
["Brush", true], 6, 15, 17, 16,
@ -966,6 +969,20 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
} else
outputs[| 0].setValue(output_surface);
}
if(live_edit) {
if(!is_struct(PANEL_FILE)) return;
var _fileO = PANEL_FILE.file_focus;
if(_fileO == noone) return;
var path = _fileO.path;
if(path == "") return;
surface_save(getCanvasSurface(0), path);
_fileO.refreshThumbnail();
}
} #endregion
static doSerialize = function(_map) { #region
@ -1009,4 +1026,38 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
static onCleanUp = function() { #region
surface_array_free(canvas_surface);
} #endregion
///////////////////////////////////
on_drop_file = function(path) { #region
loadImagePath(path);
return true;
} #endregion
static loadImagePath = function(path) { #region
if(!file_exists_empty(path)) return noone;
var _spr = sprite_add(path, 0, 0, 0, 0, 0);
if(_spr == -1) return noone;
var _sw = sprite_get_width(_spr);
var _sh = sprite_get_height(_spr);
var _s = surface_create(_sw, _sh);
surface_set_shader(_s, noone)
draw_sprite(_spr, 0, 0, 0);
surface_reset_shader();
sprite_delete(_spr);
attributes.dimension = [_sw, _sh];
inputs[| 0].setValue([_sw, _sh]);
setCanvasSurface(_s);
surface_store_buffer();
live_edit = true;
live_target = path;
return self;
} #endregion
}

View file

@ -1,7 +1,7 @@
function Node_create_CSV_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("comma separated value|*.csv", "");
path = get_open_filename_pxc("comma separated value|*.csv", "");
key_release();
if(path == "") return noone;
}

View file

@ -1,7 +1,7 @@
function Node_create_Display_Image(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("image|*.png;*.jpg", "");
path = get_open_filename_pxc("image|*.png;*.jpg", "");
key_release();
if(path == "") return noone;
}

View file

@ -1,7 +1,7 @@
function Node_create_Export(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_save_filename(@"Portable Network Graphics (.png)|*.png|
path = get_save_filename_pxc(@"Portable Network Graphics (.png)|*.png|
Joint Photographic Experts Group (.jpg)|*.jpg|
Graphics Interchange Format (.gif)|*.gif|
Animated WebP (.webp)|*.webp|

View file

@ -1,7 +1,7 @@
function Node_create_Image(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("image|*.png;*.jpg", "");
path = get_open_filename_pxc("image|*.png;*.jpg", "");
key_release();
if(path == "") return noone;
}
@ -155,7 +155,6 @@ function Node_Image(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
_splice.inputs[| 1].setValue([ ww, hh ]);
_splice.inputs[| 2].setValue(amo);
_splice.inputs[| 3].setValue([ amo, 1 ]);
_splice.inspector1Update();
#endregion
} #endregion

View file

@ -1,7 +1,7 @@
function Node_create_Image_gif(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("animated gif|*.gif", "");
path = get_open_filename_pxc("animated gif|*.gif", "");
key_release();
if(path == "") return noone;
}

View file

@ -1,7 +1,7 @@
function Node_create_Json_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("JSON file|*.json", "");
path = get_open_filename_pxc("JSON file|*.json", "");
key_release();
if(path == "") return noone;
}

View file

@ -1,7 +1,7 @@
function Node_create_Text_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("text file|*.txt", "");
path = get_open_filename_pxc("text file|*.txt", "");
key_release();
if(path == "") return noone;
}

View file

@ -1206,7 +1206,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
editWidget.align = fa_left;
editWidget.side_button = button(function() {
var path = display_data.filter == "dir"? get_directory("") : get_open_filename(display_data.filter, "");
var path = display_data.filter == "dir"? get_directory("") : get_open_filename_pxc(display_data.filter, "");
key_release();
if(path == "") return noone;
return setValueInspector(path);
@ -1220,7 +1220,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
editWidget.align = fa_left;
editWidget.side_button = button(function() {
var path = get_save_filename(display_data.filter, "");
var path = get_save_filename_pxc(display_data.filter, "");
key_release();
if(path == "") return noone;
return setValueInspector(path);

View file

@ -1,7 +1,7 @@
function Node_create_WAV_File_Read(_x, _y, _group = noone) { #region
var path = "";
if(NODE_NEW_MANUAL) {
path = get_open_filename("audio|*.wav", "");
path = get_open_filename_pxc("audio|*.wav", "");
key_release();
if(path == "") return noone;
}

View file

@ -31,9 +31,9 @@ function ExpFile(path) constructor {
th_h = 1;
static getThumbnail = function() {
if(thumbnail == -1)
if(thumbnail == -1)
return noone;
else if(thumbnail != noone)
else if(thumbnail != noone && sprite_exists(thumbnail))
return thumbnail;
thumbnail = -1;
@ -60,6 +60,12 @@ function ExpFile(path) constructor {
return thumbnail;
}
static refreshThumbnail = function() {
if(sprite_exists(thumbnail))
sprite_delete(thumbnail);
thumbnail = noone;
}
static destroy = function() {
if(load_thumb) sprite_delete(thumbnail);
}
@ -148,13 +154,16 @@ function Panel_File_Explorer() : PanelContent() constructor {
return;
}
rootFile = new ExpRoot();
rootFile = new ExpRoot();
root = "";
PREFERENCES.file_explorer = root;
} setRoot(PREFERENCES.file_explorer);
view_mode = PREFERENCES.file_explorer_view;
view_mode_tooltip = new tooltipSelector(__txt("View mode"), [ __txt("List"), __txt("Grid") ]);
scroll_y = 0;
scroll_y_to = 0;
scroll_y_max = 0;
@ -176,11 +185,38 @@ function Panel_File_Explorer() : PanelContent() constructor {
file_drag_mx = 0;
file_drag_my = 0;
draggable = true;
frame_dragging = false;
frame_drag_mx = false;
frame_drag_my = false;
path_dragging = -1;
file_focus = noone;
#region menu
__menu_file_selecting = noone;
menu_file_image = [
menuItem("Add as node", function() {
var _graph_x = (PANEL_GRAPH.w / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_x;
var _graph_y = (PANEL_GRAPH.h / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_y;
Node_create_Image_path(_graph_x, _graph_y, __menu_file_selecting.path);
}),
menuItem("Add as canvas", function() {
var _graph_x = (PANEL_GRAPH.w / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_x;
var _graph_y = (PANEL_GRAPH.h / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_y;
nodeBuild("Node_Canvas", _graph_x, _graph_y).loadImagePath(__menu_file_selecting.path);
}),
];
menu_file_project = [ menuItem("Open", function() { LOAD_AT(__menu_file_selecting.path); }), ];
#endregion
function onFocusBegin() { PANEL_FILE = self; }
contentPane = new scrollPane(w - padding - padding - cntPad * 2, h - padding - top_bar - cntPad * 2, function(_y, _m, _r) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
@ -188,18 +224,20 @@ function Panel_File_Explorer() : PanelContent() constructor {
if(frame_dragging) file_selectings = [];
file_hovering = noone;
draggable = true;
var _h = drawDir(rootFile, 0, _y, contentPane.surface_w, _m);
if(frame_dragging) draw_sprite_stretched_points_clamp(THEME.ui_selection, 0, frame_drag_mx, frame_drag_my, _m[0], _m[1], COLORS._main_accent);
if(mouse_press(mb_left, pFOCUS)) {
if(draggable && mouse_press(mb_left, pFOCUS)) {
if(file_hovering == noone) {
file_selectings = [];
frame_dragging = true;
frame_drag_mx = _m[0];
frame_drag_my = _m[1];
} else {
} else {
if(!array_exists(file_selectings, file_hovering))
file_selectings = [ file_hovering ];
path_dragging = -1;
@ -220,8 +258,30 @@ function Panel_File_Explorer() : PanelContent() constructor {
}
if(mouse_release(mb_left)) {
if(path_dragging != -1 && !pHOVER)
o_main.load_file_path(path_dragging);
file_focus = noone;
if(path_dragging != -1 && !array_empty(path_dragging) && !pHOVER) {
var _dropped = false;
if(HOVER && is_instanceof(HOVER, Panel)) {
var _cont = HOVER.getContent();
if(is_instanceof(_cont, Panel_Preview)) {
var _node = _cont.getNodePreview();
if(_node && _node.on_drop_file) {
_node.on_drop_file(path_dragging[0]);
_dropped = true;
}
}
if(array_length(file_selectings) == 1)
file_focus = file_selectings[0];
}
if(!_dropped)
o_main.load_file_path(path_dragging);
}
file_dragging = false;
path_dragging = -1;
@ -232,14 +292,11 @@ function Panel_File_Explorer() : PanelContent() constructor {
} );
function onResize() { #region
initSize();
contentPane.resize(w - padding - padding - cntPad * 2, h - padding - top_bar - cntPad * 2);
} #endregion
function drawDir(dirObject, _x, _y, _w, _m) {
var _h = 0;
var _sy = _y;
@ -247,7 +304,11 @@ function Panel_File_Explorer() : PanelContent() constructor {
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text);
var _ith = line_get_height() + ui(4);
var _graph_x = (PANEL_GRAPH.w / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_x;
var _graph_y = (PANEL_GRAPH.h / 2) / PANEL_GRAPH.graph_s - PANEL_GRAPH.graph_y;
for (var i = 0, n = array_length(dirObject.directories); i < n; i++) {
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text);
var _dir = dirObject.directories[i];
var _px = _x + ui(2);
@ -259,10 +320,14 @@ function Panel_File_Explorer() : PanelContent() constructor {
var _ppw = _pw;
if(point_in_rectangle(_m[0], _m[1], _px, _py, _px + _pw, _py + _ph)) {
if(buttonInstant(THEME.button_hide, _px + _ppw - _ph, _py, _ph, _ph, _m, pFOCUS, pHOVER, "", THEME.path_open_20) == 2) {
if(buttonInstant(THEME.button_hide, _px + _ppw - _ph, _py, _ph, _ph, _m, pFOCUS, pHOVER, "", THEME.path_open_20) == 2)
setRoot(_dir.path);
}
_ppw -= _ph + ui(4);
_ppw -= _ph + ui(2);
if(buttonInstant(THEME.button_hide, _px + _ppw - _ph, _py, _ph, _ph, _m, pFOCUS, pHOVER, "", THEME.copy_20) == 2)
clipboard_set_text(_dir.path);
_ppw -= _ph + ui(2);
}
if(contentPane.hover && point_in_rectangle(_m[0], _m[1], _px, _py, _px + _ppw, _py + _ph)) {
@ -274,6 +339,9 @@ function Panel_File_Explorer() : PanelContent() constructor {
_dir.getContent();
_dir.open = !_dir.open;
}
// if(mouse_press(mb_right)) menuCall("",,, [ menuItem("Delete", function() {}) ]);
}
draw_sprite_stretched(THEME.ui_panel_bg, _ind, _px, _py, _ppw, _ph);
@ -296,57 +364,179 @@ function Panel_File_Explorer() : PanelContent() constructor {
}
}
for (var i = 0, n = array_length(dirObject.files); i < n; i++) {
var _fil = dirObject.files[i];
if(array_length(dirObject.files)) {
_h += ui(4);
_sy += ui(4);
}
if(view_mode == FILE_EXPLORER_VIEW.list) {
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text);
var _px = _x + ui(2);
var _py = _sy + ui(2);
var _pw = _w - ui(4);
var _ph = _ith;
var _tw = ui(4) + _ph + string_width(_fil.name) + ui(8);
if(frame_dragging && rectangle_in_rectangle(_px, _py, _px + _tw, _py + _ph, frame_drag_mx, frame_drag_my, _m[0], _m[1]))
array_push(file_selectings, _fil);
var _sel = array_exists(file_selectings, _fil);
var _tx = _px + ui(2);
var _ty = _py + ui(2);
var _th = _fil.getThumbnail();
draw_set_color(c_white);
gpu_set_colorwriteenable(1, 1, 1, 0);
draw_rectangle(_px, _py, _px + _tw, _py + _ph, false);
gpu_set_colorwriteenable(1, 1, 1, 1);
if(_sel) draw_sprite_stretched_ext(THEME.ui_panel_bg, 4, _px, _py, _tw, _ph, merge_color(COLORS._main_icon_dark, COLORS._main_icon, 0.3), 1);
if(contentPane.hover && point_in_rectangle(_m[0], _m[1], _px, _py, _px + _tw, _py + _ph)) {
if(!mouse_click(mb_left)) {
draw_sprite_stretched_ext(THEME.ui_panel_fg, 1, _px, _py, _tw, _ph, COLORS._main_icon_light, 1);
TOOLTIP = [ _th, "sprite" ];
for (var i = 0, n = array_length(dirObject.files); i < n; i++) {
var _fil = dirObject.files[i];
var _px = _x + ui(2);
var _py = _sy + ui(2);
var _pw = _w - ui(4);
var _ph = _ith;
var _tw = ui(4) + _ph + string_width(_fil.name) + ui(8);
if(frame_dragging && rectangle_in_rectangle(_px, _py, _px + _tw, _py + _ph, frame_drag_mx, frame_drag_my, _m[0], _m[1]))
array_push(file_selectings, _fil);
var _sel = array_exists(file_selectings, _fil);
var _tx = _px + ui(2);
var _ty = _py + ui(2);
var _th = _fil.getThumbnail();
draw_set_color(c_white);
gpu_set_colorwriteenable(1, 1, 1, 0);
draw_rectangle(_px, _py, _px + _tw, _py + _ph, false);
gpu_set_colorwriteenable(1, 1, 1, 1);
if(_sel) draw_sprite_stretched_ext(THEME.ui_panel_bg, 4, _px, _py, _tw, _ph, merge_color(COLORS._main_icon_dark, COLORS._main_icon, 0.3), 1);
if(point_in_rectangle(_m[0], _m[1], _px, _py, _px + _pw, _py + _ph)) {
var _bx = _px + _tw + ui(4);
if(path_is_image(_fil.path)) {
if(buttonInstant(noone, _bx, _py, _ph, _ph, _m, pFOCUS, pHOVER, "", THEME.image_20, 0, [ COLORS._main_icon, c_white ]) == 2) {
Node_create_Image_path(_graph_x, _graph_y, _fil.path);
draggable = false;
} _bx += _ph + ui(2);
if(buttonInstant(noone, _bx, _py, _ph, _ph, _m, pFOCUS, pHOVER, "", THEME.canvas_20, 0, [ COLORS._main_icon, c_white ]) == 2) {
nodeBuild("Node_Canvas", _graph_x, _graph_y).loadImagePath(_fil.path);
draggable = false;
} _bx += _ph + ui(2);
} else if(path_is_project(_fil.path)) {
if(buttonInstant(noone, _bx, _py, _ph, _ph, _m, pFOCUS, pHOVER, "", THEME.path_open_20, 0, [ COLORS._main_icon, c_white ]) == 2) {
LOAD_AT(_fil.path);
draggable = false;
} _bx += _ph + ui(2);
}
}
file_hovering = _fil;
if(mouse_press(mb_left) && key_mod_press(CTRL)) {
if(_sel) array_remove(file_selectings, _fil);
else array_push(file_selectings, _fil);
if(contentPane.hover && point_in_rectangle(_m[0], _m[1], _px, _py, _px + _tw, _py + _ph)) {
if(!mouse_click(mb_left)) {
draw_sprite_stretched_ext(THEME.ui_panel_fg, 1, _px, _py, _tw, _ph, COLORS._main_icon_light, 1);
TOOLTIP = [ _th, "sprite" ];
}
file_hovering = _fil;
if(pFOCUS && mouse_press(mb_left) && key_mod_press(CTRL)) {
if(_sel) array_remove(file_selectings, _fil);
else array_push(file_selectings, _fil);
}
if(pFOCUS && mouse_press(mb_right)) {
__menu_file_selecting = _fil;
if(path_is_image(_fil.path))
menuCall("",,, menu_file_image);
else if(path_is_project(_fil.path))
menuCall("",,, menu_file_project);
}
if(pFOCUS && DOUBLE_CLICK)
o_main.load_file_path([ _fil.path ], _graph_x, _graph_y);
}
if(sprite_exists(_th)) {
var _ths = min(1, (_ph - ui(4)) / _fil.th_w, (_ph - ui(4)) / _fil.th_h);
draw_sprite_ext(_th, 0, _tx + _ph / 2, _py + _ph / 2, _ths, _ths, 0, c_white, 1);
}
_tx += _ph + ui(4);
draw_set_color(_fil == file_focus? COLORS._main_value_positive : COLORS._main_text);
draw_text_add(_tx, _ty, _fil.name);
_h += _ith + ui(2);
_sy += _ith + ui(2);
}
if(sprite_exists(_th)) {
var _ths = min(1, (_ph - ui(4)) / _fil.th_w, (_ph - ui(4)) / _fil.th_h);
draw_sprite_ext(_th, 0, _tx + _ph / 2, _py + _ph / 2, _ths, _ths, 0, c_white, 1);
} else if(view_mode == FILE_EXPLORER_VIEW.grid) {
var _grid_width = ui(80);
var _grid_height = ui(64);
var _grid_spac = ui(4);
var _title_heigh = ui(24);
draw_set_text(f_p3, fa_center, fa_bottom, COLORS._main_text);
var _col = floor(_w / (_grid_width + _grid_spac));
_grid_width = (_w - (_col - 1) * _grid_spac) / _col;
for (var i = 0, n = array_length(dirObject.files); i < n; i++) {
var _fil = dirObject.files[i];
var _cind = i % _col;
var _rind = floor(i / _col);
var _px = _x + _cind * (_grid_width + _grid_spac);
var _py = _sy + _rind * (_grid_height + _title_heigh + _grid_spac);
var _pw = _grid_width;
var _ph = _grid_height + _title_heigh;
if(frame_dragging && rectangle_in_rectangle(_px, _py, _px + _pw, _py + _ph, frame_drag_mx, frame_drag_my, _m[0], _m[1]))
array_push(file_selectings, _fil);
var _sel = array_exists(file_selectings, _fil);
var _tx = _px + _grid_width / 2;
var _ty = _py + _grid_height + _title_heigh;
var _th = _fil.getThumbnail();
draw_set_color(c_white);
gpu_set_colorwriteenable(1, 1, 1, 0);
draw_rectangle(_px, _py, _px + _pw, _py + _ph, false);
gpu_set_colorwriteenable(1, 1, 1, 1);
if(_sel) draw_sprite_stretched_ext(THEME.ui_panel_bg, 4, _px, _py, _pw, _ph, merge_color(COLORS._main_icon_dark, COLORS._main_icon, 0.3), 1);
if(contentPane.hover && point_in_rectangle(_m[0], _m[1], _px, _py, _px + _pw, _py + _ph)) {
if(!mouse_click(mb_left)) {
draw_sprite_stretched_ext(THEME.ui_panel_fg, 1, _px, _py, _pw, _ph, COLORS._main_icon_light, 1);
TOOLTIP = [ _th, "sprite" ];
}
file_hovering = _fil;
if(pFOCUS && mouse_press(mb_left) && key_mod_press(CTRL)) {
if(_sel) array_remove(file_selectings, _fil);
else array_push(file_selectings, _fil);
}
if(pFOCUS && mouse_press(mb_right)) {
__menu_file_selecting = _fil;
if(path_is_image(_fil.path))
menuCall("",,, menu_file_image);
else if(path_is_project(_fil.path))
menuCall("",,, menu_file_project);
}
if(pFOCUS && DOUBLE_CLICK)
o_main.load_file_path([ _fil.path ], _graph_x, _graph_y);
}
if(sprite_exists(_th)) {
var _ths = min((_grid_width - ui(4)) / _fil.th_w, (_grid_height - ui(4)) / _fil.th_h);
draw_sprite_ext(_th, 0, _px + _grid_width / 2, _py + _grid_height / 2, _ths, _ths, 0, c_white, 1);
}
draw_set_color(_fil == file_focus? COLORS._main_value_positive : COLORS._main_text);
draw_text_ext_add(_tx, _ty, _fil.name, -1, _grid_width, 1, true);
}
_tx += _ph + ui(4);
draw_set_color(COLORS._main_text);
draw_text_add(_tx, _ty, _fil.name);
_h += _ith + ui(2);
_sy += _ith + ui(2);
var n = array_length(dirObject.files);
_h += ceil(n / _col) * (_grid_height + _title_heigh + _grid_spac);
}
return _h;
@ -369,9 +559,15 @@ function Panel_File_Explorer() : PanelContent() constructor {
var tb_x = cnt_x + ui(32);
var tb_y = pad;
var tb_w = w - pad - tb_x;
var tb_w = w - pad - tb_x - bs - ui(4);
var tb_h = top_bar - pad - ui(8);
if(buttonInstant(THEME.button_hide, w - pad - bs, pad, bs, bs, [mx, my], pFOCUS, pHOVER, view_mode_tooltip, THEME.view_mode, !view_mode) == 2) {
view_mode = !view_mode;
PREFERENCES.file_explorer_view = view_mode;
}
view_mode_tooltip.index = view_mode;
tb_root.setFocusHover(pFOCUS, pHOVER);
tb_root.font = f_p2;
tb_root.draw(tb_x, tb_y, tb_w, tb_h, root, [mx, my]);
@ -381,8 +577,8 @@ function Panel_File_Explorer() : PanelContent() constructor {
}
function drawGUI() {
if(path_dragging != -1) {
for (var i = 0, n = array_length(file_selectings); i < n; i++) {
var f = file_selectings[i];
@ -391,7 +587,7 @@ function Panel_File_Explorer() : PanelContent() constructor {
mouse_my + 20 + 8 * i,
1, 1, 0, c_white, 1);
} else if(is_instanceof(f, ExpDir)) {
} else if(is_instanceof(f, ExpFile)) {
var _s = 64 / max(f.th_w, f.th_h);
if(f.thumbnail) draw_sprite_ext(f.thumbnail, 0, mouse_mx + f.th_w * _s / 2 + 8 * i,
mouse_my + f.th_h * _s / 2 + 8 * i,

View file

@ -1,5 +1,5 @@
#region data
globalvar PANEL_MAIN, PANEL_MENU, PANEL_PREVIEW, PANEL_INSPECTOR, PANEL_GRAPH, PANEL_ANIMATION, PANEL_COLLECTION;
globalvar PANEL_MAIN, PANEL_MENU, PANEL_PREVIEW, PANEL_INSPECTOR, PANEL_GRAPH, PANEL_ANIMATION, PANEL_COLLECTION, PANEL_FILE;
globalvar FULL_SCREEN_PANEL, FULL_SCREEN_CONTENT, FULL_SCREEN_PARENT;
PANEL_MAIN = 0;
@ -43,6 +43,8 @@
PANEL_PREVIEW = {};
PANEL_GRAPH = {};
PANEL_COLLECTION = {};
PANEL_FILE = 0;
} #endregion
function getPanelFromName(name, create = false) { #region
@ -51,7 +53,7 @@
case "Panel_Inspector" : var p = (create || findPanel(name))? new Panel_Inspector() : PANEL_INSPECTOR; PANEL_INSPECTOR = p; return p;
case "Panel_Animation" : var p = (create || findPanel(name))? new Panel_Animation() : PANEL_ANIMATION; PANEL_ANIMATION = p; return p;
case "Panel_Preview" : var p = (create || findPanel(name))? new Panel_Preview() : PANEL_PREVIEW; PANEL_PREVIEW = p; return p;
case "Panel_Graph" : var p = (create || findPanel(name))? new Panel_Graph() : PANEL_GRAPH; PANEL_GRAPH = p; return p;
case "Panel_Graph" : var p = (create || findPanel(name))? new Panel_Graph() : PANEL_GRAPH; PANEL_GRAPH = p; return p;
case "Panel_Collection" : return new Panel_Collection();
case "Panel_Workspace" : return new Panel_Workspace();
@ -61,7 +63,7 @@
case "Panel_Nodes" : return new Panel_Nodes();
case "Panel_Globalvar" : return new Panel_Globalvar();
case "Panel_Node_Align" : return new Panel_Node_Align();
case "Panel_File_Explorer" : return new Panel_File_Explorer();
case "Panel_File_Explorer" : var p = (create || findPanel(name))? new Panel_File_Explorer() : PANEL_FILE; PANEL_FILE = p; return p;
case "Panel_Color" : return new Panel_Color();
case "Panel_Palette" : return new Panel_Palette();

View file

@ -1814,7 +1814,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
context_frame_ey = context_frame_sy + 16;
} #endregion
function drawContent(panel) { #region >>>>>>>>>>>>>>>>>>>> MAIN DRAW <<<<<<<<<<<<<<<<<<<<
function drawContent(panel) { #region MAIN DRAW
if(!project.active) return;
dragGraph();

View file

@ -53,7 +53,7 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor {
b_export = button(function() { #region
if(!is_surface(surface)) return;
var path = get_save_filename("image|*.png;*.jpg", "Screenshot");
var path = get_save_filename_pxc("image|*.png;*.jpg", "Screenshot");
if(path == -1) return;
if(filename_ext(path) != ".png") path += ".png";

View file

@ -1015,10 +1015,8 @@ function Panel_Inspector() : PanelContent() constructor {
var bx = w - ui(44);
var by = ui(12);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txtx("panel_inspector_set_default", "Set Metadata as default"), THEME.save, 0, COLORS._main_icon) == 2) {
var path = DIRECTORY + "meta.json";
json_save_struct(path, PROJECT.meta.serialize());
}
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txtx("panel_inspector_set_default", "Set Metadata as default"), THEME.save, 0, COLORS._main_icon) == 2)
json_save_struct(DIRECTORY + "meta.json", PROJECT.meta.serialize());
by += ui(36);
if(STEAM_ENABLED && !workshop_uploading) {

View file

@ -85,7 +85,7 @@ function Panel_Palette() : PanelContent() constructor {
}),
-1,
menuItem(__txtx("palette_editor_set_default", "Set as default"), function() {
DEF_PALETTE = array_clone(hovering.palette);
PROJECT.setPalette(array_clone(hovering.palette));
}),
menuItem(__txtx("palette_editor_delete", "Delete palette"), function() {
file_delete(hovering.path);

View file

@ -2,6 +2,7 @@
function __fnInit_Preview() {
__registerFunction("preview_focus_content", panel_preview_focus_content);
__registerFunction("preview_save_current_frame", panel_preview_save_current_frame);
__registerFunction("preview_saveCurrentFrameToFocus", panel_preview_saveCurrentFrameToFocus);
__registerFunction("preview_save_all_current_frame", panel_preview_save_all_current_frame);
__registerFunction("preview_preview_window", panel_preview_preview_window);
__registerFunction("preview_toggle_grid", panel_preview_toggle_grid);
@ -12,6 +13,7 @@
function panel_preview_focus_content() { CALL("preview_focus_content"); PANEL_PREVIEW.fullView(); }
function panel_preview_save_current_frame() { CALL("preview_save_current_frame"); PANEL_PREVIEW.saveCurrentFrame(); }
function panel_preview_saveCurrentFrameToFocus() { CALL("preview_saveCurrentFrameToFocus"); PANEL_PREVIEW.saveCurrentFrameToFocus(); }
function panel_preview_save_all_current_frame() { CALL("preview_save_all_current_frame"); PANEL_PREVIEW.saveAllCurrentFrames(); }
function panel_preview_preview_window() { CALL("preview_preview_window"); PANEL_PREVIEW.create_preview_window(PANEL_PREVIEW.getNodePreview()); }
function panel_preview_toggle_grid() { CALL("preview_toggle_grid"); PROJECT.previewGrid.show = !PROJECT.previewGrid.show; }
@ -212,7 +214,8 @@ function Panel_Preview() : PanelContent() constructor {
#region ++++ hotkey ++++
addHotkey("Preview", "Focus content", "F", MOD_KEY.none, panel_preview_focus_content);
addHotkey("Preview", "Save current frame", "S", MOD_KEY.shift, panel_preview_save_current_frame);
addHotkey("Preview", "Save all current frame", -1, MOD_KEY.none, panel_preview_save_all_current_frame);
addHotkey("Preview", "Save to focused file", "", MOD_KEY.none, panel_preview_saveCurrentFrameToFocus);
addHotkey("Preview", "Save all current frame", "", MOD_KEY.none, panel_preview_save_all_current_frame);
addHotkey("Preview", "Preview window", "P", MOD_KEY.ctrl, panel_preview_preview_window);
addHotkey("Preview", "Toggle grid", "G", MOD_KEY.ctrl, panel_preview_toggle_grid);
@ -302,7 +305,8 @@ function Panel_Preview() : PanelContent() constructor {
],
];
tooltip_center = new tooltipHotkey(__txtx("panel_preview_center_canvas", "Center canvas"), "Preview", "Focus content");
tooltip_center = new tooltipHotkey(__txtx("panel_preview_center_canvas", "Center canvas"), "Preview", "Focus content");
tooltip_export = new tooltipHotkey(__txtx("panel_preview_export_canvas", "Export canvas"), "Preview", "Save current frame");
actions = [
[
@ -313,7 +317,7 @@ function Panel_Preview() : PanelContent() constructor {
],
[
THEME.icon_preview_export,
__txtx("panel_preview_export_canvas", "Export canvas"),
tooltip_export,
function() { saveCurrentFrame(); },
function() { return 0; },
],
@ -1782,12 +1786,31 @@ function Panel_Preview() : PanelContent() constructor {
clipboard_set_bitmap(buffer_get_address(buff), surface_get_width_safe(prevS), surface_get_height_safe(prevS));
} #endregion
function saveCurrentFrameToFocus() { #region
var prevS = getNodePreviewSurface();
var _node = getNodePreview();
if(!is_surface(prevS)) return;
if(!is_struct(PANEL_FILE)) return;
var _fileO = PANEL_FILE.file_focus;
if(_fileO == noone) return;
var path = _fileO.path;
if(path == "") return;
if(filename_ext(path) != ".png") path += ".png";
surface_save_safe(prevS, path);
_fileO.refreshThumbnail();
} #endregion
function saveCurrentFrame() { #region
var prevS = getNodePreviewSurface();
var _node = getNodePreview();
if(!is_surface(prevS)) return;
var path = get_save_filename("image|*.png;*.jpg", _node.display_name == ""? "export" : _node.display_name);
var path = get_save_filename_pxc("image|*.png;*.jpg", _node.display_name == ""? "export" : _node.display_name, "Save surface as");
key_release();
if(path == "") return;
if(filename_ext(path) != ".png") path += ".png";
@ -1796,7 +1819,7 @@ function Panel_Preview() : PanelContent() constructor {
} #endregion
function saveAllCurrentFrames() { #region
var path = get_save_filename("image|*.png;*.jpg", _node.display_name == ""? "export" : _node.display_name);
var path = get_save_filename_pxc("image|*.png;*.jpg", _node.display_name == ""? "export" : _node.display_name, "Save surfaces as");
key_release();
if(path == "") return;

View file

@ -63,3 +63,15 @@ function path_is_image(path) {
}
return false;
}
function path_is_project(path) {
if(!file_exists_empty(path)) return false;
var ext = filename_ext(path);
switch(ext) {
case ".pxc":
case ".pxcc":
return true;
}
return false;
}

View file

@ -58,6 +58,8 @@
PREFERENCES.dialog_add_node_h = 400;
PREFERENCES.add_node_remember = true;
PREFERENCES.file_explorer_view = FILE_EXPLORER_VIEW.list;
#endregion
@ -136,11 +138,16 @@
PREFERENCES.ffmpeg_path = "%APP%/ffmpeg/";
PREFERENCES.file_explorer = "";
PREFERENCES.dialog_path = "";
PREFERENCES.versions = {};
#endregion
#region ///////////////////////////////////////////////////////////////////////// DATA //////////////////////////////////////////////////////////////////////////
PREFERENCES.attr_palette = [ cola(c_black), cola(c_white) ];
#endregion
PREFERENCES_DEF = variable_clone(PREFERENCES);
#endregion
@ -250,6 +257,9 @@
struct_override(PREFERENCES, map.preferences);
if(!is_array(PREFERENCES.attr_palette))
PREFERENCES.attr_palette = PREFERENCES_DEF.attr_palette;
if(!directory_exists($"{DIRECTORY}Themes/{PREFERENCES.theme}"))
PREFERENCES.theme = "default";

View file

@ -62,7 +62,7 @@
attributes = {
strict : false,
surface_dimension : [ 32, 32 ],
palette : [ cola(c_black), cola(c_white) ],
palette : array_clone(PREFERENCES.attr_palette),
palette_fix : false,
}
@ -114,7 +114,10 @@
static setPalette = function(pal = noone) {
if(pal != noone) attributes.palette = pal;
PREFERENCES.attr_palette = array_clone(pal);
palettes = paletteToArray(attributes.palette);
} setPalette();
#endregion

View file

@ -95,7 +95,7 @@ function SAVE(project = PROJECT) { #region
function SAVE_AS(project = PROJECT) { #region
if(DEMO) return false;
var path = get_save_filename("Pixel Composer project (.pxc)|*.pxc|Compressed Pixel Composer project (.cpxc)|*.cpxc", "");
var path = get_save_filename_pxc("Pixel Composer project (.pxc)|*.pxc|Compressed Pixel Composer project (.cpxc)|*.cpxc", "");
key_release();
if(path == "") return false;