mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-25 06:26:42 +01:00
Image asset dragging between panels.
This commit is contained in:
parent
30c57e121c
commit
3d106a11c7
6 changed files with 71 additions and 63 deletions
|
@ -82,6 +82,16 @@
|
||||||
draw_rectangle(mouse_mx + ui(-16), mouse_my + ui(-16), mouse_mx + ui(-16 + 32), mouse_my + ui(-16 + 32), false);
|
draw_rectangle(mouse_mx + ui(-16), mouse_my + ui(-16), mouse_mx + ui(-16 + 32), mouse_my + ui(-16 + 32), false);
|
||||||
draw_set_alpha(1);
|
draw_set_alpha(1);
|
||||||
break;
|
break;
|
||||||
|
case "Asset" :
|
||||||
|
var ss = 32 / max(sprite_get_width(DRAGGING.data.spr), sprite_get_height(DRAGGING.data.spr))
|
||||||
|
draw_sprite_ext(DRAGGING.data.spr, 0, mouse_mx, mouse_my, ss, ss, 0, c_white, 0.5);
|
||||||
|
break;
|
||||||
|
case "Collection" :
|
||||||
|
if(DRAGGING.data.spr) {
|
||||||
|
var ss = 32 / max(sprite_get_width(DRAGGING.data.spr), sprite_get_height(DRAGGING.data.spr))
|
||||||
|
draw_sprite_ext(DRAGGING.data.spr, 0, mouse_mx, mouse_my, ss, ss, 0, c_white, 0.5);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mouse_release(mb_left))
|
if(mouse_release(mb_left))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
function APPEND(_path, record = true) {
|
function APPEND(_path, context = PANEL_GRAPH.getCurrentContext()) {
|
||||||
if(_path == "") return noone;
|
if(_path == "") return noone;
|
||||||
var _map = json_load(_path);
|
var _map = json_load(_path);
|
||||||
|
|
||||||
|
@ -7,14 +7,14 @@ function APPEND(_path, record = true) {
|
||||||
return noone;
|
return noone;
|
||||||
}
|
}
|
||||||
|
|
||||||
var node_create = __APPEND_MAP(_map);
|
var node_create = __APPEND_MAP(_map, context);
|
||||||
if(record) recordAction(ACTION_TYPE.collection_loaded, array_create_from_list(node_create), _path);
|
recordAction(ACTION_TYPE.collection_loaded, array_create_from_list(node_create), _path);
|
||||||
log_message("FILE", "append file " + _path, THEME.noti_icon_file_load);
|
log_message("FILE", "append file " + _path, THEME.noti_icon_file_load);
|
||||||
|
|
||||||
return node_create;
|
return node_create;
|
||||||
}
|
}
|
||||||
|
|
||||||
function __APPEND_MAP(_map) {
|
function __APPEND_MAP(_map, context = PANEL_GRAPH.getCurrentContext()) {
|
||||||
static log = false;
|
static log = false;
|
||||||
APPENDING = true;
|
APPENDING = true;
|
||||||
UNDO_HOLDING = true;
|
UNDO_HOLDING = true;
|
||||||
|
@ -48,7 +48,7 @@ function __APPEND_MAP(_map) {
|
||||||
var _node = appended_list[| i];
|
var _node = appended_list[| i];
|
||||||
_node.loadGroup();
|
_node.loadGroup();
|
||||||
|
|
||||||
if(_node.group == PANEL_GRAPH.getCurrentContext())
|
if(_node.group == context)
|
||||||
ds_list_add(node_create, _node);
|
ds_list_add(node_create, _node);
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
|
@ -6,6 +6,18 @@ function FileObject(_name, _path) constructor {
|
||||||
content = -1;
|
content = -1;
|
||||||
surface = noone;
|
surface = noone;
|
||||||
meta = noone;
|
meta = noone;
|
||||||
|
type = FILE_TYPE.collection;
|
||||||
|
|
||||||
|
switch(string_lower(filename_ext(path))) {
|
||||||
|
case ".png" :
|
||||||
|
case ".jpg" :
|
||||||
|
case ".gif" :
|
||||||
|
type = FILE_TYPE.assets;
|
||||||
|
break;
|
||||||
|
case ".pxc" :
|
||||||
|
type = FILE_TYPE.project;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
retrive_data = false;
|
retrive_data = false;
|
||||||
thumbnail_data = -1;
|
thumbnail_data = -1;
|
||||||
|
|
|
@ -168,7 +168,7 @@ function Panel_Collection() : PanelContent() constructor {
|
||||||
if(_hover && point_in_rectangle(_m[0], _m[1], _nx, yy, _nx + grid_width, yy + grid_size)) {
|
if(_hover && point_in_rectangle(_m[0], _m[1], _nx, yy, _nx + grid_width, yy + grid_size)) {
|
||||||
draw_sprite_stretched_ext(THEME.node_active, 0, _boxx, yy, grid_size, grid_size, COLORS._main_accent, 1);
|
draw_sprite_stretched_ext(THEME.node_active, 0, _boxx, yy, grid_size, grid_size, COLORS._main_accent, 1);
|
||||||
if(mouse_press(mb_left, pFOCUS))
|
if(mouse_press(mb_left, pFOCUS))
|
||||||
file_dragging = _node;
|
DRAGGING = { type : _node.type == FILE_TYPE.collection? "Collection" : "Asset", data : _node }
|
||||||
|
|
||||||
if(!DEMO && mouse_press(mb_right, pFOCUS)) {
|
if(!DEMO && mouse_press(mb_right, pFOCUS)) {
|
||||||
_menu_node = _node;
|
_menu_node = _node;
|
||||||
|
@ -242,7 +242,7 @@ function Panel_Collection() : PanelContent() constructor {
|
||||||
if(_hover && point_in_rectangle(_m[0], _m[1], 0, yy, list_width, yy + list_height - 1)) {
|
if(_hover && point_in_rectangle(_m[0], _m[1], 0, yy, list_width, yy + list_height - 1)) {
|
||||||
draw_sprite_stretched_ext(THEME.node_active, 0, ui(4), yy, list_width - ui(8), list_height, COLORS._main_accent, 1);
|
draw_sprite_stretched_ext(THEME.node_active, 0, ui(4), yy, list_width - ui(8), list_height, COLORS._main_accent, 1);
|
||||||
if(mouse_press(mb_left, pFOCUS))
|
if(mouse_press(mb_left, pFOCUS))
|
||||||
file_dragging = _node;
|
DRAGGING = { type : _node.type == FILE_TYPE.collection? "Collection" : "Asset", data : _node }
|
||||||
|
|
||||||
if(!DEMO && mouse_press(mb_right, pFOCUS)) {
|
if(!DEMO && mouse_press(mb_right, pFOCUS)) {
|
||||||
_menu_node = _node;
|
_menu_node = _node;
|
||||||
|
@ -461,58 +461,4 @@ function Panel_Collection() : PanelContent() constructor {
|
||||||
tb_search.draw(tb_x, tb_y, tb_w, TEXTBOX_HEIGHT, search_string, [mx, my]);
|
tb_search.draw(tb_x, tb_y, tb_w, TEXTBOX_HEIGHT, search_string, [mx, my]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawGUI() {
|
|
||||||
if(file_dragging) {
|
|
||||||
if(file_dragging.spr)
|
|
||||||
draw_sprite_ext(file_dragging.spr, 0, mouse_mx, mouse_my, 1, 1, 0, c_white, 0.5);
|
|
||||||
|
|
||||||
if(panelHover(PANEL_GRAPH))
|
|
||||||
dragToGraph(HOVER.getContent());
|
|
||||||
|
|
||||||
if(mouse_release(mb_left))
|
|
||||||
file_dragging = noone;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static dragToGraph = function(graph) {
|
|
||||||
var path = file_dragging.path;
|
|
||||||
ds_list_clear(graph.nodes_select_list);
|
|
||||||
|
|
||||||
if(string_lower(filename_ext(path)) == ".png") {
|
|
||||||
var app = Node_create_Image_path(0, 0, path);
|
|
||||||
|
|
||||||
graph.node_focus = app;
|
|
||||||
graph.node_dragging = app;
|
|
||||||
graph.node_drag_sx = app.x;
|
|
||||||
graph.node_drag_sy = app.y;
|
|
||||||
} else {
|
|
||||||
var app = APPEND(file_dragging.path);
|
|
||||||
|
|
||||||
if(!is_struct(app) && ds_exists(app, ds_type_list)) {
|
|
||||||
graph.node_focus = noone;
|
|
||||||
ds_list_copy(graph.nodes_select_list, app);
|
|
||||||
|
|
||||||
if(!ds_list_empty(app)) {
|
|
||||||
graph.node_dragging = app[| 0];
|
|
||||||
graph.node_drag_sx = app[| 0].x;
|
|
||||||
graph.node_drag_sy = app[| 0].y;
|
|
||||||
}
|
|
||||||
ds_list_destroy(app);
|
|
||||||
} else {
|
|
||||||
graph.node_focus = app;
|
|
||||||
graph.node_dragging = app;
|
|
||||||
graph.node_drag_sx = app.x;
|
|
||||||
graph.node_drag_sy = app.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
graph.node_drag_mx = 0;
|
|
||||||
graph.node_drag_my = 0;
|
|
||||||
|
|
||||||
graph.node_drag_ox = 0;
|
|
||||||
graph.node_drag_oy = 0;
|
|
||||||
|
|
||||||
file_dragging = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1749,6 +1749,38 @@ function Panel_Graph() : PanelContent() constructor {
|
||||||
var node = nodeBuild("Node_Palette", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
var node = nodeBuild("Node_Palette", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
||||||
node.inputs[| 0].setValue(DRAGGING.data);
|
node.inputs[| 0].setValue(DRAGGING.data);
|
||||||
break;
|
break;
|
||||||
|
case "Asset":
|
||||||
|
var app = Node_create_Image_path(mouse_grid_x, mouse_grid_y, DRAGGING.data.path);
|
||||||
|
break;
|
||||||
|
case "Collection":
|
||||||
|
var path = DRAGGING.data.path;
|
||||||
|
ds_list_clear(nodes_select_list);
|
||||||
|
|
||||||
|
var app = APPEND(DRAGGING.data.path, getCurrentContext());
|
||||||
|
|
||||||
|
if(!is_struct(app) && ds_exists(app, ds_type_list)) {
|
||||||
|
var cx = 0;
|
||||||
|
var cy = 0;
|
||||||
|
|
||||||
|
for( var i = 0; i < ds_list_size(app); i++ ) {
|
||||||
|
cx += app[| i].x;
|
||||||
|
cy += app[| i].y;
|
||||||
|
}
|
||||||
|
|
||||||
|
cx /= ds_list_size(app);
|
||||||
|
cy /= ds_list_size(app);
|
||||||
|
|
||||||
|
for( var i = 0; i < ds_list_size(app); i++ ) {
|
||||||
|
app[| i].x = app[| i].x - cx + mouse_grid_x;
|
||||||
|
app[| i].y = app[| i].y - cy + mouse_grid_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
ds_list_destroy(app);
|
||||||
|
} else {
|
||||||
|
app.x = mouse_grid_x;
|
||||||
|
app.y = mouse_grid_y;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,12 @@ function surfaceBox(_onModify, def_path = "") : widget() constructor {
|
||||||
open_rx = _rx;
|
open_rx = _rx;
|
||||||
open_ry = _ry;
|
open_ry = _ry;
|
||||||
|
|
||||||
|
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h);
|
||||||
|
|
||||||
if(!open) {
|
if(!open) {
|
||||||
draw_sprite_stretched(THEME.textbox, 3, _x, _y, _w, _h);
|
draw_sprite_stretched(THEME.textbox, 3, _x, _y, _w, _h);
|
||||||
|
|
||||||
if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h)) {
|
if(hover && hoverRect) {
|
||||||
draw_sprite_stretched(THEME.textbox, 1, _x, _y, _w, _h);
|
draw_sprite_stretched(THEME.textbox, 1, _x, _y, _w, _h);
|
||||||
if(mouse_press(mb_left, active))
|
if(mouse_press(mb_left, active))
|
||||||
trigger();
|
trigger();
|
||||||
|
@ -70,6 +72,12 @@ function surfaceBox(_onModify, def_path = "") : widget() constructor {
|
||||||
if(WIDGET_CURRENT == self)
|
if(WIDGET_CURRENT == self)
|
||||||
draw_sprite_stretched(THEME.widget_selecting, 0, _x - ui(3), _y - ui(3), _w + ui(6), _h + ui(6));
|
draw_sprite_stretched(THEME.widget_selecting, 0, _x - ui(3), _y - ui(3), _w + ui(6), _h + ui(6));
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
resetFocus();
|
resetFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue