mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-25 06:26:42 +01:00
Globalize Palette, Gradient data. png palette.
This commit is contained in:
parent
468ebbd5f3
commit
d8c5fd2d3d
17 changed files with 229 additions and 240 deletions
|
@ -625,7 +625,7 @@
|
|||
{"name":"__node_custom","order":14,"path":"scripts/__node_custom/__node_custom.yy",},
|
||||
{"name":"s_node_note","order":35,"path":"sprites/s_node_note/s_node_note.yy",},
|
||||
{"name":"node_strand_gravity","order":4,"path":"scripts/node_strand_gravity/node_strand_gravity.yy",},
|
||||
{"name":"load_palette","order":3,"path":"scripts/load_palette/load_palette.yy",},
|
||||
{"name":"palette_functions","order":3,"path":"scripts/palette_functions/palette_functions.yy",},
|
||||
{"name":"luaHighlight","order":1,"path":"scripts/luaHighlight/luaHighlight.yy",},
|
||||
{"name":"d3d_rot3","order":3,"path":"scripts/d3d_rot3/d3d_rot3.yy",},
|
||||
{"name":"sh_sample_points","order":26,"path":"shaders/sh_sample_points/sh_sample_points.yy",},
|
||||
|
|
|
@ -1228,7 +1228,7 @@
|
|||
{"id":{"name":"node_surface_data","path":"scripts/node_surface_data/node_surface_data.yy",},},
|
||||
{"id":{"name":"s_node_note","path":"sprites/s_node_note/s_node_note.yy",},},
|
||||
{"id":{"name":"node_strand_gravity","path":"scripts/node_strand_gravity/node_strand_gravity.yy",},},
|
||||
{"id":{"name":"load_palette","path":"scripts/load_palette/load_palette.yy",},},
|
||||
{"id":{"name":"palette_functions","path":"scripts/palette_functions/palette_functions.yy",},},
|
||||
{"id":{"name":"sh_alpha_cutoff","path":"shaders/sh_alpha_cutoff/sh_alpha_cutoff.yy",},},
|
||||
{"id":{"name":"luaHighlight","path":"scripts/luaHighlight/luaHighlight.yy",},},
|
||||
{"id":{"name":"d3d_rot3","path":"scripts/d3d_rot3/d3d_rot3.yy",},},
|
||||
|
|
|
@ -32,27 +32,7 @@ event_inherited();
|
|||
#endregion
|
||||
|
||||
#region presets
|
||||
presets = ds_list_create();
|
||||
preset_name = ds_list_create();
|
||||
preset_selecting = 0;
|
||||
|
||||
function presetCollect() {
|
||||
ds_list_clear(presets);
|
||||
ds_list_clear(preset_name);
|
||||
|
||||
ds_list_add(presets, DEF_PALETTE);
|
||||
ds_list_add(preset_name, "Project");
|
||||
|
||||
var path = DIRECTORY + "Palettes/"
|
||||
var file = file_find_first(path + "*", 0);
|
||||
while(file != "") {
|
||||
ds_list_add(presets, loadPalette(path + file));
|
||||
ds_list_add(preset_name, filename_name(file));
|
||||
file = file_find_next();
|
||||
}
|
||||
file_find_close();
|
||||
}
|
||||
presetCollect();
|
||||
preset_selecting = -1;
|
||||
|
||||
sp_preset_w = ui(240 - 32 - 16);
|
||||
sp_preset_size = ui(24);
|
||||
|
@ -67,8 +47,13 @@ event_inherited();
|
|||
var _hover = sHOVER && sp_presets.hover;
|
||||
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
||||
|
||||
for(var i = 0; i < ds_list_size(presets); i++) {
|
||||
pre_amo = array_length(presets[| i]);
|
||||
for(var i = -1; i < array_length(PALETTES); i++) {
|
||||
var pal = i == -1? {
|
||||
name: "project",
|
||||
palette: PROJECT.attributes.palette,
|
||||
path: ""
|
||||
} : PALETTES[i];
|
||||
pre_amo = array_length(pal.palette);
|
||||
var col = floor(ww / _gs);
|
||||
var row = ceil(pre_amo / col);
|
||||
|
||||
|
@ -83,19 +68,19 @@ event_inherited();
|
|||
if(isHover)
|
||||
draw_sprite_stretched_ext(THEME.node_active, 1, ui(4), yy, sp_preset_w - ui(16), _height, COLORS._main_accent, 1);
|
||||
|
||||
var x0 = ui(16) + (i == 0) * ui(8 + 6);
|
||||
var x0 = ui(16) + (i == -1) * ui(8 + 6);
|
||||
var cc = i == preset_selecting? COLORS._main_accent : COLORS._main_text_sub;
|
||||
draw_set_text(f_p2, fa_left, fa_top, cc);
|
||||
draw_text(x0, yy + ui(8), preset_name[| i]);
|
||||
if(i == 0) {
|
||||
draw_text(x0, yy + ui(8), pal.name);
|
||||
if(i == -1) {
|
||||
draw_set_color(cc);
|
||||
draw_circle_prec(ui(16) + ui(4), yy + ui(16), ui(4), false);
|
||||
}
|
||||
|
||||
if(preset_selecting == i)
|
||||
drawPaletteGrid(presets[| i], ui(16), yy + ui(28), ww, _gs, selector.current_color);
|
||||
drawPaletteGrid(pal.palette, ui(16), yy + ui(28), ww, _gs, selector.current_color);
|
||||
else
|
||||
drawPalette(presets[| i], ui(16), yy + ui(28), ww, ui(20));
|
||||
drawPalette(pal.palette, ui(16), yy + ui(28), ww, ui(20));
|
||||
|
||||
if(!click_block && mouse_click(mb_left, interactable && sFOCUS)) {
|
||||
if(preset_selecting == i && _hover && point_in_rectangle(_m[0], _m[1], ui(16), yy + ui(28), ui(16) + ww, yy + ui(28) + _height)) {
|
||||
|
@ -107,7 +92,7 @@ event_inherited();
|
|||
|
||||
var _index = m_gy * col + m_gx;
|
||||
if(_index < pre_amo && _index >= 0) {
|
||||
selector.setColor(presets[| i][_index]);
|
||||
selector.setColor(pal.palette[_index]);
|
||||
selector.setHSV();
|
||||
}
|
||||
} else if(isHover) {
|
||||
|
|
|
@ -60,7 +60,7 @@ if !ready exit;
|
|||
var col_y = dialog_y + ui(52);
|
||||
|
||||
if(preset_selecting > -1)
|
||||
selector.palette = presets[| preset_selecting];
|
||||
selector.palette = PALETTES[preset_selecting].palette;
|
||||
selector.draw(col_x, col_y, sFOCUS, sHOVER);
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -83,24 +83,6 @@ event_inherited();
|
|||
#endregion
|
||||
|
||||
#region preset
|
||||
presets = ds_list_create();
|
||||
preset_name = ds_list_create();
|
||||
|
||||
function presetCollect() {
|
||||
ds_list_clear(presets);
|
||||
ds_list_clear(preset_name);
|
||||
|
||||
var path = DIRECTORY + "Gradients/"
|
||||
var file = file_find_first(path + "*", 0);
|
||||
while(file != "") {
|
||||
ds_list_add(presets, loadGradient(path + file));
|
||||
ds_list_add(preset_name, filename_name(file));
|
||||
file = file_find_next();
|
||||
}
|
||||
file_find_close();
|
||||
}
|
||||
presetCollect();
|
||||
|
||||
hovering_name = "";
|
||||
sp_preset_w = ui(240 - 32 - 16);
|
||||
sp_presets = new scrollPane(sp_preset_w, dialog_h - ui(62), function(_y, _m) {
|
||||
|
@ -111,29 +93,30 @@ event_inherited();
|
|||
var _hover = sHOVER && sp_presets.hover;
|
||||
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
||||
|
||||
for(var i = 0; i < ds_list_size(presets); i++) {
|
||||
var isHover = point_in_rectangle(_m[0], _m[1], ui(4), yy, ui(4) + sp_preset_w - ui(16), yy + hg);
|
||||
for(var i = 0; i < array_length(GRADIENTS); i++) {
|
||||
var _gradient = GRADIENTS[i];
|
||||
var isHover = point_in_rectangle(_m[0], _m[1], ui(4), yy, ui(4) + sp_preset_w - ui(16), yy + hg);
|
||||
|
||||
draw_sprite_stretched(THEME.ui_panel_bg, 1, ui(4), yy, sp_preset_w - ui(16), hg);
|
||||
if(_hover && isHover)
|
||||
draw_sprite_stretched_ext(THEME.node_active, 1, ui(4), yy, sp_preset_w - ui(16), hg, COLORS._main_accent, 1);
|
||||
|
||||
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
|
||||
draw_text(ui(16), yy + ui(8), filename_name_only(preset_name[| i]));
|
||||
presets[| i].draw(ui(16), yy + ui(28), ww, ui(16));
|
||||
draw_text(ui(16), yy + ui(8), _gradient.name);
|
||||
_gradient.gradient.draw(ui(16), yy + ui(28), ww, ui(16));
|
||||
|
||||
if(_hover && isHover) {
|
||||
if(mouse_press(mb_left, interactable && sFOCUS))
|
||||
gradient.keys = presets[| i].keys;
|
||||
gradient.keys = _gradient.gradient.keys;
|
||||
|
||||
if(mouse_press(mb_right, interactable && sFOCUS)) {
|
||||
hovering_name = preset_name[| i];
|
||||
hovering_name = _gradient.path;
|
||||
menuCall("gradient_window_preset_menu",,, [
|
||||
menuItem(__txtx("gradient_editor_delete", "Delete gradient"), function() {
|
||||
file_delete( DIRECTORY + "Gradients/" + hovering_name);
|
||||
presetCollect();
|
||||
file_delete(hovering_name);
|
||||
__initGradient();
|
||||
})
|
||||
],, { name: hovering_name })
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,27 +129,7 @@ event_inherited();
|
|||
#endregion
|
||||
|
||||
#region palette
|
||||
palettes = ds_list_create();
|
||||
palette_name = ds_list_create();
|
||||
palette_selecting = 0;
|
||||
|
||||
function paletteCollect() {
|
||||
ds_list_clear(palettes);
|
||||
ds_list_clear(palette_name);
|
||||
|
||||
ds_list_add(palettes, DEF_PALETTE);
|
||||
ds_list_add(palette_name, "Project");
|
||||
|
||||
var path = DIRECTORY + "Palettes/"
|
||||
var file = file_find_first(path + "*", 0);
|
||||
while(file != "") {
|
||||
ds_list_add(palettes, loadPalette(path + file));
|
||||
ds_list_add(palette_name, filename_name(file));
|
||||
file = file_find_next();
|
||||
}
|
||||
file_find_close();
|
||||
}
|
||||
paletteCollect();
|
||||
palette_selecting = -1;
|
||||
|
||||
sp_palette_w = ui(240 - 32 - 16);
|
||||
sp_palette_size = ui(24);
|
||||
|
@ -181,8 +144,14 @@ event_inherited();
|
|||
var _hover = sHOVER && sp_palettes.hover;
|
||||
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
||||
|
||||
for(var i = 0; i < ds_list_size(palettes); i++) {
|
||||
pre_amo = array_length(palettes[| i]);
|
||||
for(var i = -1; i < array_length(PALETTES); i++) {
|
||||
var pal = i == -1? {
|
||||
name: "project",
|
||||
palette: PROJECT.attributes.palette,
|
||||
path: ""
|
||||
} : PALETTES[i];
|
||||
|
||||
pre_amo = array_length(pal.palette);
|
||||
var col = floor(ww / _gs);
|
||||
var row = ceil(pre_amo / col);
|
||||
|
||||
|
@ -197,19 +166,19 @@ event_inherited();
|
|||
if(isHover)
|
||||
draw_sprite_stretched_ext(THEME.node_active, 1, ui(4), yy, sp_palette_w - ui(16), _height, COLORS._main_accent, 1);
|
||||
|
||||
var x0 = ui(16) + (i == 0) * ui(8 + 6);
|
||||
var x0 = ui(16) + (i == -1) * ui(8 + 6);
|
||||
var cc = i == palette_selecting? COLORS._main_accent : COLORS._main_text_sub;
|
||||
draw_set_text(f_p2, fa_left, fa_top, cc);
|
||||
draw_text(x0, yy + ui(8), filename_name_only(palette_name[| i]));
|
||||
if(i == 0) {
|
||||
draw_text(x0, yy + ui(8), pal.name);
|
||||
if(i == -1) {
|
||||
draw_set_color(cc);
|
||||
draw_circle_prec(ui(16) + ui(4), yy + ui(16), ui(4), false);
|
||||
}
|
||||
|
||||
if(palette_selecting == i)
|
||||
drawPaletteGrid(palettes[| i], ui(16), yy + ui(28), ww, _gs);
|
||||
drawPaletteGrid(pal.palette, ui(16), yy + ui(28), ww, _gs);
|
||||
else
|
||||
drawPalette(palettes[| i], ui(16), yy + ui(28), ww, ui(20));
|
||||
drawPalette(pal.palette, ui(16), yy + ui(28), ww, ui(20));
|
||||
|
||||
if(!click_block && mouse_click(mb_left, interactable && sFOCUS)) {
|
||||
if(palette_selecting == i && _hover && point_in_rectangle(_m[0], _m[1], ui(16), yy + ui(28), ui(16) + ww, yy + ui(28) + _height)) {
|
||||
|
@ -221,7 +190,7 @@ event_inherited();
|
|||
|
||||
var _index = m_gy * col + m_gx;
|
||||
if(_index < pre_amo && _index >= 0) {
|
||||
selector.setColor(palettes[| i][_index]);
|
||||
selector.setColor(pal.palette[_index]);
|
||||
selector.setHSV();
|
||||
}
|
||||
} else if(isHover) {
|
||||
|
|
|
@ -214,7 +214,7 @@ if !ready exit;
|
|||
var col_y = dialog_y + ui(136);
|
||||
|
||||
if(palette_selecting > -1)
|
||||
selector.palette = palettes[| palette_selecting];
|
||||
selector.palette = PALETTES[palette_selecting].palette;
|
||||
selector.draw(col_x, col_y, sFOCUS, sHOVER);
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -54,27 +54,6 @@ event_inherited();
|
|||
#endregion
|
||||
|
||||
#region presets
|
||||
presets = ds_list_create();
|
||||
preset_name = ds_list_create();
|
||||
|
||||
function presetCollect() {
|
||||
ds_list_clear(presets);
|
||||
ds_list_clear(preset_name);
|
||||
|
||||
ds_list_add(presets, DEF_PALETTE);
|
||||
ds_list_add(preset_name, "Project");
|
||||
|
||||
var path = DIRECTORY + "Palettes/"
|
||||
var file = file_find_first(path + "*", 0);
|
||||
while(file != "") {
|
||||
ds_list_add(presets, loadPalette(path + file));
|
||||
ds_list_add(preset_name, filename_name(file));
|
||||
file = file_find_next();
|
||||
}
|
||||
file_find_close();
|
||||
}
|
||||
presetCollect();
|
||||
|
||||
hovering_name = "";
|
||||
|
||||
sp_preset_w = ui(240 - 32 - 16);
|
||||
|
@ -85,31 +64,36 @@ event_inherited();
|
|||
var hg = ui(52);
|
||||
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
||||
|
||||
for(var i = 0; i < ds_list_size(presets); i++) {
|
||||
for(var i = -1; i < array_length(PALETTES); i++) {
|
||||
var pal = i == -1? {
|
||||
name: "project",
|
||||
palette: PROJECT.attributes.palette,
|
||||
path: ""
|
||||
} : PALETTES[i];
|
||||
var isHover = sHOVER && sp_presets.hover && point_in_rectangle(_m[0], _m[1], ui(4), yy, ui(4) + sp_preset_w - ui(16), yy + hg);
|
||||
draw_sprite_stretched(THEME.ui_panel_bg, 1, ui(4), yy, sp_preset_w - ui(16), hg);
|
||||
if(isHover)
|
||||
draw_sprite_stretched_ext(THEME.node_active, 1, ui(4), yy, sp_preset_w - ui(16), hg, COLORS._main_accent, 1);
|
||||
|
||||
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
|
||||
draw_text(ui(16), yy + ui(8), filename_name_only(preset_name[| i]));
|
||||
drawPalette(presets[| i], ui(16), yy + ui(28), ww, ui(16));
|
||||
draw_text(ui(16), yy + ui(8), pal.name);
|
||||
drawPalette(pal.palette, ui(16), yy + ui(28), ww, ui(16));
|
||||
|
||||
if(isHover) {
|
||||
if(mouse_press(mb_left, interactable && sFOCUS)) {
|
||||
palette = array_create(array_length(presets[| i]));
|
||||
for( var j = 0; j < array_length(presets[| i]); j++ )
|
||||
palette[j] = presets[| i][j];
|
||||
palette = array_create(array_length(pal.palette));
|
||||
for( var j = 0; j < array_length(pal.palette); j++ )
|
||||
palette[j] = pal.palette[j];
|
||||
}
|
||||
|
||||
if(mouse_press(mb_right, interactable && sFOCUS)) {
|
||||
hovering_name = preset_name[| i];
|
||||
hovering_name = pal.name;
|
||||
menuCall("palette_window_preset_menu",,, [
|
||||
menuItem(__txtx("palette_editor_delete", "Delete palette"), function() {
|
||||
file_delete( DIRECTORY + "Palettes/" + hovering_name);
|
||||
presetCollect();
|
||||
file_delete(hovering_name);
|
||||
__initPalette();
|
||||
})
|
||||
],, { name : hovering_name })
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -184,7 +184,8 @@ if palette == 0 exit;
|
|||
if(buttonInstant(THEME.button, 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", "");
|
||||
key_release();
|
||||
if(path != "") {
|
||||
|
||||
if(isPaletteFile(path)) {
|
||||
palette = loadPalette(path);
|
||||
onApply(palette);
|
||||
}
|
||||
|
|
|
@ -82,6 +82,8 @@
|
|||
log_message("SESSION", "> init Nodes"); __initNodes();
|
||||
log_message("SESSION", "> init SteamUGC"); __initSteamUGC();
|
||||
log_message("SESSION", "> init Addon"); __initAddon();
|
||||
log_message("SESSION", "> init Palette"); __initPalette();
|
||||
log_message("SESSION", "> init Gradient"); __initGradient();
|
||||
|
||||
setPanel();
|
||||
loadAddon();
|
||||
|
|
|
@ -6,18 +6,18 @@ function draw_circle_prec(x, y, r, border, precision = 32) {
|
|||
function draw_circle_border(xx, yy, r, w) {
|
||||
var step = 32;
|
||||
var angle_step = 360 / step;
|
||||
|
||||
var px, py, _px, _py;
|
||||
|
||||
for(var i = 0; i <= step; i++){
|
||||
var px = xx + lengthdir_x(r, i * angle_step);
|
||||
var py = yy + lengthdir_y(r, i * angle_step);
|
||||
|
||||
if(i) draw_line_round(_px, _py, px, py, w);
|
||||
draw_primitive_begin(pr_trianglestrip);
|
||||
for(var i = 0; i <= step; i++){
|
||||
var p0x = xx + lengthdir_x(r - w / 2, i * angle_step);
|
||||
var p0y = yy + lengthdir_y(r - w / 2, i * angle_step);
|
||||
var p1x = xx + lengthdir_x(r + w / 2, i * angle_step);
|
||||
var p1y = yy + lengthdir_y(r + w / 2, i * angle_step);
|
||||
|
||||
_px = px;
|
||||
_py = py;
|
||||
draw_vertex(p0x, p0y);
|
||||
draw_vertex(p1x, p1y);
|
||||
}
|
||||
draw_primitive_end();
|
||||
}
|
||||
|
||||
function draw_ellipse_border(x0, y0, x1, y1, w) {
|
||||
|
|
|
@ -4,34 +4,31 @@ enum GRADIENT_INTER {
|
|||
hue
|
||||
}
|
||||
|
||||
function gradientKey(time, value) constructor {
|
||||
function gradientKey(time, value) constructor { #region
|
||||
self.time = time;
|
||||
self.value = value;
|
||||
|
||||
static clone = function() { return new gradientKey(time, value); }
|
||||
|
||||
static serialize = function() { return { time, value }; }
|
||||
}
|
||||
} #endregion
|
||||
|
||||
function gradientObject(color = c_black) constructor {
|
||||
function gradientObject(color = c_black) constructor { #region
|
||||
static GRADIENT_LIMIT = 128;
|
||||
|
||||
if(is_array(color))
|
||||
keys = [ new gradientKey(0, color[0]), new gradientKey(1, color[1]) ];
|
||||
else
|
||||
keys = [ new gradientKey(0, color) ];
|
||||
if(is_array(color)) keys = [ new gradientKey(0, color[0]), new gradientKey(1, color[1]) ];
|
||||
else keys = [ new gradientKey(0, color) ];
|
||||
type = GRADIENT_INTER.smooth;
|
||||
|
||||
static clone = function() {
|
||||
static clone = function() { #region
|
||||
var g = new gradientObject();
|
||||
for( var i = 0, n = array_length(keys); i < n; i++ )
|
||||
g.keys[i] = keys[i].clone();
|
||||
g.type = type;
|
||||
|
||||
return g;
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static add = function(_addkey, _deleteDup = true) {
|
||||
static add = function(_addkey, _deleteDup = true) { #region
|
||||
if(array_length(keys) > GRADIENT_LIMIT) return;
|
||||
if(array_length(keys) == 0) {
|
||||
array_push(keys, _addkey);
|
||||
|
@ -52,9 +49,9 @@ function gradientObject(color = c_black) constructor {
|
|||
}
|
||||
|
||||
array_push(keys, _addkey);
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static eval = function(position) {
|
||||
static eval = function(position) { #region
|
||||
if(array_length(keys) == 0) return c_black;
|
||||
if(array_length(keys) == 1) return keys[0].value;
|
||||
|
||||
|
@ -77,9 +74,9 @@ function gradientObject(color = c_black) constructor {
|
|||
}
|
||||
|
||||
return keys[array_length(keys) - 1].value; //after last color
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static draw = function(_x, _y, _w, _h, _a = 1) {
|
||||
static draw = function(_x, _y, _w, _h, _a = 1) { #region
|
||||
var uniform_grad_blend = shader_get_uniform(sh_gradient_display, "gradient_blend");
|
||||
var uniform_grad = shader_get_uniform(sh_gradient_display, "gradient_color");
|
||||
var uniform_grad_time = shader_get_uniform(sh_gradient_display, "gradient_time");
|
||||
|
@ -112,9 +109,9 @@ function gradientObject(color = c_black) constructor {
|
|||
draw_sprite_stretched_ext(s_fx_pixel, 0, _x, _y, _w, _h, c_white, _a)
|
||||
shader_reset();
|
||||
}
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static toArray = function() {
|
||||
static toArray = function() { #region
|
||||
var _grad_color = [], _grad_time = [];
|
||||
|
||||
for(var i = 0; i < array_length(keys); i++) {
|
||||
|
@ -128,9 +125,9 @@ function gradientObject(color = c_black) constructor {
|
|||
}
|
||||
|
||||
return [ _grad_color, _grad_time ];
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static lerpTo = function(target, amount) {
|
||||
static lerpTo = function(target, amount) { #region
|
||||
var grad = new gradientObject();
|
||||
grad.keys = [];
|
||||
grad.type = type;
|
||||
|
@ -150,9 +147,9 @@ function gradientObject(color = c_black) constructor {
|
|||
}
|
||||
|
||||
return grad;
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static shader_submit = function() {
|
||||
static shader_submit = function() { #region
|
||||
var _grad = toArray();
|
||||
var _grad_color = _grad[0];
|
||||
var _grad_time = _grad[1];
|
||||
|
@ -161,9 +158,9 @@ function gradientObject(color = c_black) constructor {
|
|||
shader_set_f("gradient_color", _grad_color);
|
||||
shader_set_f("gradient_time", _grad_time);
|
||||
shader_set_i("gradient_keys", array_length(keys));
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static clone = function() {
|
||||
static clone = function() { #region
|
||||
var g = new gradientObject();
|
||||
g.keys = [];
|
||||
g.type = type;
|
||||
|
@ -172,18 +169,18 @@ function gradientObject(color = c_black) constructor {
|
|||
g.keys[i] = keys[i].clone();
|
||||
|
||||
return g;
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static serialize = function() {
|
||||
static serialize = function() { #region
|
||||
var s = { type: type };
|
||||
s.keys = [];
|
||||
for( var i = 0, n = array_length(keys); i < n; i++ )
|
||||
s.keys[i] = keys[i].serialize();
|
||||
|
||||
return json_stringify(s, false);
|
||||
}
|
||||
} #endregion
|
||||
|
||||
static deserialize = function(str) {
|
||||
static deserialize = function(str) { #region
|
||||
var s;
|
||||
|
||||
if(is_string(str))
|
||||
|
@ -208,10 +205,10 @@ function gradientObject(color = c_black) constructor {
|
|||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
} #endregion
|
||||
} #endregion
|
||||
|
||||
function loadGradient(path) {
|
||||
function loadGradient(path) { #region
|
||||
if(path == "") return noone;
|
||||
if(!file_exists(path)) return noone;
|
||||
|
||||
|
@ -240,4 +237,23 @@ function loadGradient(path) {
|
|||
file_text_close(_t);
|
||||
|
||||
return grad;
|
||||
} #endregion
|
||||
|
||||
globalvar GRADIENTS;
|
||||
GRADIENTS = [];
|
||||
|
||||
function __initGradient() {
|
||||
GRADIENTS = [];
|
||||
|
||||
var path = DIRECTORY + "Gradients/"
|
||||
var file = file_find_first(path + "*", 0);
|
||||
while(file != "") {
|
||||
array_push(GRADIENTS, {
|
||||
name: filename_name_only(file),
|
||||
path: path + file,
|
||||
gradient: loadGradient(path + file)
|
||||
});
|
||||
file = file_find_next();
|
||||
}
|
||||
file_find_close();
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
function loadPalette(path) {
|
||||
var pal = [];
|
||||
|
||||
if(path != "" && file_exists(path)) {
|
||||
var _t = file_text_open_read(path);
|
||||
var _index = 0;
|
||||
var ext = string_lower(filename_ext(path));
|
||||
while(!file_text_eof(_t)) {
|
||||
var _w = file_text_readln(_t);
|
||||
if(_w != "") {
|
||||
switch(ext) {
|
||||
case ".hex" :
|
||||
var _r = string_hexadecimal(string_copy(_w, 1, 2));
|
||||
var _g = string_hexadecimal(string_copy(_w, 3, 2));
|
||||
var _b = string_hexadecimal(string_copy(_w, 5, 2));
|
||||
|
||||
pal[_index++] = make_color_rgb(_r, _g, _b);
|
||||
break;
|
||||
case ".gpl" :
|
||||
case ".pal" :
|
||||
if(string_char_at(_w, 1) == "#") break;
|
||||
var _c = string_splice(_w, " ");
|
||||
if(array_length(_c) >= 3)
|
||||
pal[_index++] = make_color_rgb(toNumber(_c[0]), toNumber(_c[1]), toNumber(_c[2]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
file_text_close(_t);
|
||||
}
|
||||
return pal;
|
||||
}
|
|
@ -20,10 +20,15 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|||
|
||||
outputs[| 0] = nodeValue("Out", self, JUNCTION_CONNECT.output, VALUE_TYPE.any, 0);
|
||||
|
||||
static update = function(frame = CURRENT_FRAME) {
|
||||
inputs[| 0].setType(inputs[| 0].value_from == noone? VALUE_TYPE.any : inputs[| 0].value_from.type);
|
||||
outputs[| 0].setType(inputs[| 0].type);
|
||||
static step = function() {
|
||||
if(inputs[| 0].value_from == noone) return;
|
||||
|
||||
inputs[| 0].setType(inputs[| 0].value_from.type);
|
||||
outputs[| 0].setType(inputs[| 0].value_from.type);
|
||||
outputs[| 0].value_from = inputs[| 0].value_from;
|
||||
|
||||
inputs[| 0].color_display = inputs[| 0].value_from.color_display;
|
||||
outputs[| 0].color_display = inputs[| 0].color_display;
|
||||
}
|
||||
|
||||
static pointIn = function(_x, _y, _mx, _my, _s) {
|
||||
|
@ -77,8 +82,13 @@ function Node_Pin(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
|||
active_draw_index = -1;
|
||||
}
|
||||
|
||||
if(hover_scale > 0)
|
||||
draw_sprite_ext(THEME.node_pin_bg_active, 0, xx, yy, _s * hover_scale, _s * hover_scale, 0, COLORS._main_accent, hover_alpha);
|
||||
if(hover_scale > 0) {
|
||||
draw_set_color(COLORS._main_accent);
|
||||
draw_set_alpha(hover_alpha);
|
||||
draw_circle_border(xx, yy, _s * hover_scale * 20, 2);
|
||||
draw_set_alpha(1);
|
||||
}
|
||||
|
||||
hover_scale = lerp_float(hover_scale, hover_scale_to, 3);
|
||||
hover_scale_to = 0;
|
||||
|
||||
|
|
91
scripts/palette_functions/palette_functions.gml
Normal file
91
scripts/palette_functions/palette_functions.gml
Normal file
|
@ -0,0 +1,91 @@
|
|||
function isPaletteFile(path) { #region
|
||||
var ext = string_lower(filename_ext(path));
|
||||
switch(ext) {
|
||||
case ".hex" :
|
||||
case ".gpl" :
|
||||
case ".pal" :
|
||||
case ".png" :
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} #endregion
|
||||
|
||||
function loadPalette(path) { #region
|
||||
if(!file_exists(path)) return [];
|
||||
if(!isPaletteFile(path)) return [];
|
||||
|
||||
var ext = string_lower(filename_ext(path));
|
||||
|
||||
if(ext == ".png") {
|
||||
var _spr = sprite_add(path, 1, 0, 0, 0, 0);
|
||||
var _sw = sprite_get_width(_spr);
|
||||
var _sh = sprite_get_height(_spr);
|
||||
var _s = surface_create(_sw, _sh);
|
||||
surface_set_target(_s);
|
||||
draw_clear_alpha(0, 0);
|
||||
BLEND_OVERRIDE
|
||||
draw_sprite(_spr, 0, 0, 0);
|
||||
BLEND_NORMAL
|
||||
surface_reset_target();
|
||||
|
||||
var pal = array_create(_sw * _sh);
|
||||
for( var i = 0; i < _sh; i++ )
|
||||
for( var j = 0; j < _sw; j++ )
|
||||
pal[i * _sh + j] = surface_getpixel(_s, j, i);
|
||||
|
||||
surface_free(_s);
|
||||
|
||||
return pal;
|
||||
}
|
||||
|
||||
var pal = [];
|
||||
var _t = file_text_open_read(path);
|
||||
var _index = 0;
|
||||
|
||||
while(!file_text_eof(_t)) {
|
||||
var _w = file_text_readln(_t);
|
||||
if(_w == "") continue;
|
||||
|
||||
switch(ext) {
|
||||
case ".hex" :
|
||||
var _r = string_hexadecimal(string_copy(_w, 1, 2));
|
||||
var _g = string_hexadecimal(string_copy(_w, 3, 2));
|
||||
var _b = string_hexadecimal(string_copy(_w, 5, 2));
|
||||
|
||||
pal[_index++] = make_color_rgb(_r, _g, _b);
|
||||
break;
|
||||
case ".gpl" :
|
||||
case ".pal" :
|
||||
if(string_char_at(_w, 1) == "#") break;
|
||||
var _c = string_splice(_w, " ");
|
||||
if(array_length(_c) >= 3)
|
||||
pal[_index++] = make_color_rgb(toNumber(_c[0]), toNumber(_c[1]), toNumber(_c[2]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
file_text_close(_t);
|
||||
|
||||
return pal;
|
||||
} #endregion
|
||||
|
||||
globalvar PALETTES;
|
||||
PALETTES = [];
|
||||
|
||||
function __initPalette() {
|
||||
PALETTES = [];
|
||||
|
||||
var path = DIRECTORY + "Palettes/"
|
||||
var file = file_find_first(path + "*", 0);
|
||||
while(file != "") {
|
||||
if(isPaletteFile(file)) {
|
||||
array_push(PALETTES, {
|
||||
name: filename_name_only(file),
|
||||
path: path + file,
|
||||
palette: loadPalette(path + file)
|
||||
});
|
||||
}
|
||||
file = file_find_next();
|
||||
}
|
||||
file_find_close();
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"resourceType": "GMScript",
|
||||
"resourceVersion": "1.0",
|
||||
"name": "load_palette",
|
||||
"name": "palette_functions",
|
||||
"isCompatibility": false,
|
||||
"isDnD": false,
|
||||
"parent": {
|
|
@ -7,25 +7,6 @@ function Panel_Gradient() : PanelContent() constructor {
|
|||
w = ui(320);
|
||||
h = ui(480);
|
||||
|
||||
presets = [];
|
||||
|
||||
function presetCollect() {
|
||||
presets = [];
|
||||
|
||||
var path = DIRECTORY + "Gradients/"
|
||||
var file = file_find_first(path + "*", 0);
|
||||
while(file != "") {
|
||||
array_push(presets, {
|
||||
name: filename_name(file),
|
||||
gradient: loadGradient(path + file)
|
||||
});
|
||||
|
||||
file = file_find_next();
|
||||
}
|
||||
file_find_close();
|
||||
}
|
||||
presetCollect();
|
||||
|
||||
function onResize() {
|
||||
PANEL_PADDING
|
||||
|
||||
|
@ -37,7 +18,7 @@ function Panel_Gradient() : PanelContent() constructor {
|
|||
var ww = sp_gradient.surface_w;
|
||||
var hh = 0;
|
||||
|
||||
var amo = array_length(presets);
|
||||
var amo = array_length(GRADIENTS);
|
||||
var col = floor(ww / ui(160));
|
||||
var row = ceil(amo / col);
|
||||
|
||||
|
@ -53,7 +34,7 @@ function Panel_Gradient() : PanelContent() constructor {
|
|||
if(ind >= amo) break;
|
||||
|
||||
var xx = j * gw;
|
||||
var preset = presets[ind];
|
||||
var preset = GRADIENTS[ind];
|
||||
var isHover = pHOVER && point_in_rectangle(_m[0], _m[1], xx, max(0, yy), xx + gw - ui(8), min(sp_gradient.h, yy + hg));
|
||||
|
||||
draw_sprite_stretched(THEME.ui_panel_bg, in_dialog, xx, yy, gw - ui(8), hg);
|
||||
|
@ -98,6 +79,6 @@ function Panel_Gradient() : PanelContent() constructor {
|
|||
var by = title_height / 2 - ui(16 + !in_dialog * 2);
|
||||
|
||||
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txt("Refresh"), THEME.refresh, 1, COLORS._main_icon) == 2)
|
||||
presetCollect();
|
||||
__initGradient();
|
||||
}
|
||||
}
|
|
@ -7,28 +7,10 @@ function Panel_Palette() : PanelContent() constructor {
|
|||
w = ui(320);
|
||||
h = ui(480);
|
||||
|
||||
presets = [];
|
||||
view_mode = 0;
|
||||
|
||||
color_dragging = noone;
|
||||
|
||||
static presetCollect = function() {
|
||||
presets = [];
|
||||
|
||||
var path = DIRECTORY + "Palettes/"
|
||||
var file = file_find_first(path + "*", 0);
|
||||
while(file != "") {
|
||||
array_push(presets, {
|
||||
name: filename_name(file),
|
||||
palette: loadPalette(path + file)
|
||||
});
|
||||
|
||||
file = file_find_next();
|
||||
}
|
||||
file_find_close();
|
||||
}
|
||||
presetCollect()
|
||||
|
||||
function onResize() {
|
||||
PANEL_PADDING
|
||||
|
||||
|
@ -48,8 +30,8 @@ function Panel_Palette() : PanelContent() constructor {
|
|||
var yy = _y;
|
||||
var _height;
|
||||
|
||||
for(var i = 0; i < array_length(presets); i++) {
|
||||
var preset = presets[i];
|
||||
for(var i = 0; i < array_length(PALETTES); i++) {
|
||||
var preset = PALETTES[i];
|
||||
var pre_amo = array_length(preset.palette);
|
||||
var col = floor((ww - ui(20)) / _gs);
|
||||
var row = ceil(pre_amo / col);
|
||||
|
|
Loading…
Reference in a new issue