mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2025-02-03 16:55:14 +01:00
Color, palette panel
This commit is contained in:
parent
f0fa4e0b6b
commit
485685b8f9
13 changed files with 387 additions and 0 deletions
1
objects/o_dialog_panel/Draw_75.gml
Normal file
1
objects/o_dialog_panel/Draw_75.gml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/// @description
|
|
@ -0,0 +1,3 @@
|
||||||
|
function node_string_regex_replace601(){
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
function node_string_regex_search600(){
|
||||||
|
|
||||||
|
}
|
173
scripts/panel_color/panel_color.gml
Normal file
173
scripts/panel_color/panel_color.gml
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
enum COLOR_SELECTOR_MODE {
|
||||||
|
hue,
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
|
function Panel_Color() : PanelContent() constructor {
|
||||||
|
title = "Color";
|
||||||
|
showHeader = false;
|
||||||
|
title_height = 64;
|
||||||
|
padding = 24;
|
||||||
|
|
||||||
|
w = ui(320);
|
||||||
|
h = ui(320);
|
||||||
|
|
||||||
|
mode = COLOR_SELECTOR_MODE.hue;
|
||||||
|
|
||||||
|
hue = 1;
|
||||||
|
sat = 1;
|
||||||
|
val = 1;
|
||||||
|
color = c_black;
|
||||||
|
|
||||||
|
drag_con = false;
|
||||||
|
drag_sel = false;
|
||||||
|
|
||||||
|
colors = [];
|
||||||
|
|
||||||
|
static setColor = function(color) {
|
||||||
|
self.color = color;
|
||||||
|
hue = color_get_hue(color) / 255;
|
||||||
|
sat = color_get_saturation(color) / 255;
|
||||||
|
val = color_get_value(color) / 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
static setHSV = function(h = hue, s = sat, v = val) {
|
||||||
|
hue = h;
|
||||||
|
sat = s;
|
||||||
|
val = v;
|
||||||
|
|
||||||
|
color = make_color_hsv(h * 255, s * 255, v * 255);
|
||||||
|
}
|
||||||
|
setHSV();
|
||||||
|
|
||||||
|
function drawContent(panel) {
|
||||||
|
PANEL_PADDING
|
||||||
|
PANEL_TITLE
|
||||||
|
|
||||||
|
var px = ui(padding);
|
||||||
|
var py = ui(title_height);
|
||||||
|
var pw = w - ui(padding + padding);
|
||||||
|
var ph = h - ui(title_height + padding);
|
||||||
|
|
||||||
|
draw_sprite_stretched(THEME.ui_panel_bg, !in_dialog, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
|
||||||
|
|
||||||
|
var cont_x = ui(padding);
|
||||||
|
var cont_y = ui(title_height);
|
||||||
|
var cont_w = w - ui(padding + padding + ui(16 + 8));
|
||||||
|
var cont_h = h - ui(title_height + padding + ui(24 + 8));
|
||||||
|
|
||||||
|
shader_set(sh_color_select_content);
|
||||||
|
shader_set_i("mode", mode);
|
||||||
|
shader_set_f("hue", hue);
|
||||||
|
shader_set_f("val", val);
|
||||||
|
draw_sprite_stretched(s_fx_pixel, 0, cont_x, cont_y, cont_w, cont_h);
|
||||||
|
|
||||||
|
var sel_x = cont_x + cont_w + ui(8);
|
||||||
|
var sel_y = ui(title_height);
|
||||||
|
var sel_w = ui(16);
|
||||||
|
var sel_h = cont_h;
|
||||||
|
|
||||||
|
shader_set(sh_color_select_side);
|
||||||
|
shader_set_i("mode", mode);
|
||||||
|
shader_set_f("hue", hue);
|
||||||
|
draw_sprite_stretched(s_fx_pixel, 0, sel_x, sel_y, sel_w, sel_h);
|
||||||
|
shader_reset();
|
||||||
|
|
||||||
|
if(drag_con) {
|
||||||
|
if(mode == 0) {
|
||||||
|
sat = clamp((mx - cont_x) / cont_w, 0, 1);
|
||||||
|
val = 1 - clamp((my - cont_y) / cont_h, 0, 1);
|
||||||
|
} else if(mode == 1) {
|
||||||
|
hue = clamp((mx - cont_x) / cont_w, 0, 1);
|
||||||
|
sat = 1 - clamp((my - cont_y) / cont_h, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
setHSV();
|
||||||
|
|
||||||
|
if(mouse_release(mb_left))
|
||||||
|
drag_con = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(drag_sel) {
|
||||||
|
if(mode == 0)
|
||||||
|
hue = clamp((my - sel_y) / sel_h, 0, 1);
|
||||||
|
else if(mode == 1)
|
||||||
|
val = 1 - clamp((my - sel_y) / sel_h, 0, 1);
|
||||||
|
|
||||||
|
setHSV();
|
||||||
|
|
||||||
|
if(mouse_release(mb_left))
|
||||||
|
drag_sel = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mouse_press(mb_left, pFOCUS)) {
|
||||||
|
if(point_in_rectangle(mx, my, cont_x, cont_y, cont_x + cont_w, cont_y + cont_h))
|
||||||
|
drag_con = true;
|
||||||
|
|
||||||
|
if(point_in_rectangle(mx, my, sel_x, sel_y, sel_x + sel_w, sel_y + sel_h))
|
||||||
|
drag_sel = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mode == 0) {
|
||||||
|
var hy = sel_y + hue * sel_h;
|
||||||
|
var cx = cont_x + sat * cont_w - ui(6);
|
||||||
|
var cy = cont_y + (1 - val) * cont_h - ui(6);
|
||||||
|
draw_sprite_stretched_ext(s_ui_base_white, 0, sel_x - ui(3), hy - ui(6), ui(16 + 6), ui(10), make_color_hsv(hue * 255, 255, 255), 1);
|
||||||
|
draw_sprite_stretched_ext(s_ui_base_white, 0, cx, cy, ui(12), ui(12), color, 1);
|
||||||
|
} else if(mode == 1) {
|
||||||
|
var vy = sel_y + (1 - val) * sel_h;
|
||||||
|
var cx = cont_x + hue * cont_w - ui(6);
|
||||||
|
var cy = cont_y + (1 - sat) * cont_h - ui(6);
|
||||||
|
draw_sprite_stretched_ext(s_ui_base_white, 0, sel_x - ui(3), vy - ui(6), ui(16 + 6), ui(10), make_color_hsv(hue * 255, 255, val * 255), 1);
|
||||||
|
draw_sprite_stretched_ext(s_ui_base_white, 0, cx, cy, ui(12), ui(12), color, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var amo = min(array_length(colors) + 1, floor((w - ui(padding * 2)) / ui(24 + 4)));
|
||||||
|
|
||||||
|
for( var i = 0; i < amo; i++ ) {
|
||||||
|
var cx = ui(padding) + ui(24 + 4) * i;
|
||||||
|
var cy = cont_y + cont_h + ui(8);
|
||||||
|
|
||||||
|
if(i == 0) {
|
||||||
|
draw_sprite_stretched_ext(s_ui_base_white, 0, cx + ui(4), cy + ui(4), ui(16), ui(16), color, 1);
|
||||||
|
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, cx, cy, ui(24), ui(24), c_white, 0.5);
|
||||||
|
|
||||||
|
if(pHOVER && point_in_rectangle(mx, my, cx, cy, cx + ui(24), cy + ui(24))) {
|
||||||
|
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, cx, cy, ui(24), ui(24), c_white, 1);
|
||||||
|
if(mouse_press(mb_left, pFOCUS)) {
|
||||||
|
array_insert(colors, 0, color);
|
||||||
|
DRAGGING = {
|
||||||
|
type: "Color",
|
||||||
|
data: color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var c = colors[i - 1];
|
||||||
|
draw_sprite_stretched_ext(s_ui_base_white, 0, cx, cy, ui(24), ui(24), c, 1);
|
||||||
|
|
||||||
|
if(mouse_press(mb_left, pFOCUS) && point_in_rectangle(mx, my, cx, cy, cx + ui(24), cy + ui(24))) {
|
||||||
|
DRAGGING = {
|
||||||
|
type: "Color",
|
||||||
|
data: c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var bx = w - ui(32 + 16);
|
||||||
|
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, "Mode", THEME.color_wheel,, c_white) == 2)
|
||||||
|
mode = !mode;
|
||||||
|
|
||||||
|
bx -= ui(32);
|
||||||
|
|
||||||
|
if(DRAGGING && DRAGGING.type == "Color" && pHOVER) {
|
||||||
|
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, 2, 2, w - 4, h - 4, COLORS._main_value_positive, 1);
|
||||||
|
if(mouse_release(mb_left))
|
||||||
|
setColor(DRAGGING.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
scripts/panel_color/panel_color.yy
Normal file
11
scripts/panel_color/panel_color.yy
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"resourceType": "GMScript",
|
||||||
|
"resourceVersion": "1.0",
|
||||||
|
"name": "panel_color",
|
||||||
|
"isCompatibility": false,
|
||||||
|
"isDnD": false,
|
||||||
|
"parent": {
|
||||||
|
"name": "colors",
|
||||||
|
"path": "folders/panels/colors.yy",
|
||||||
|
},
|
||||||
|
}
|
121
scripts/panel_palette/panel_palette.gml
Normal file
121
scripts/panel_palette/panel_palette.gml
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
function Panel_Palette() : PanelContent() constructor {
|
||||||
|
title = "Palette";
|
||||||
|
showHeader = false;
|
||||||
|
title_height = 64;
|
||||||
|
padding = 24;
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
sp_palettes.resize(w - ui(padding + padding), h - ui(title_height + padding));
|
||||||
|
}
|
||||||
|
|
||||||
|
sp_palettes = new scrollPane(w - ui(padding + padding), h - ui(title_height + padding), function(_y, _m) {
|
||||||
|
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
||||||
|
var ww = sp_palettes.surface_w;
|
||||||
|
var hh = ui(28);
|
||||||
|
var _gs = ui(24);
|
||||||
|
switch(view_mode) {
|
||||||
|
case 0 : _gs = ui(24); break;
|
||||||
|
case 1 : _gs = ui(32); break;
|
||||||
|
case 2 : _gs = ui(16); break;
|
||||||
|
}
|
||||||
|
var yy = _y;
|
||||||
|
var _height;
|
||||||
|
|
||||||
|
for(var i = 0; i < array_length(presets); i++) {
|
||||||
|
var preset = presets[i];
|
||||||
|
var pre_amo = array_length(preset.palette);
|
||||||
|
var col = floor((ww - ui(20)) / _gs);
|
||||||
|
var row = ceil(pre_amo / col);
|
||||||
|
|
||||||
|
_height = ui(34) + row * _gs;
|
||||||
|
|
||||||
|
var isHover = pHOVER && point_in_rectangle(_m[0], _m[1], 0, max(0, yy), ww, min(sp_palettes.h, yy + _height));
|
||||||
|
|
||||||
|
draw_sprite_stretched(THEME.ui_panel_bg, in_dialog, 0, yy, ww, _height);
|
||||||
|
if(isHover)
|
||||||
|
draw_sprite_stretched_ext(THEME.node_active, 1, 0, yy, ww, _height, COLORS._main_accent, 1);
|
||||||
|
|
||||||
|
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
|
||||||
|
draw_text(ui(10), yy + ui(2), preset.name);
|
||||||
|
drawPaletteGrid(preset.palette, ui(10), yy + ui(24), ww - ui(20), _gs);
|
||||||
|
|
||||||
|
if(isHover && mouse_press(mb_left, pFOCUS)) {
|
||||||
|
if(point_in_rectangle(_m[0], _m[1], ui(10), yy + ui(24), ww - ui(10), yy + ui(24) + _height)) {
|
||||||
|
var m_ax = _m[0] - ui(10);
|
||||||
|
var m_ay = _m[1] - (yy + ui(24));
|
||||||
|
|
||||||
|
var m_gx = floor(m_ax / _gs);
|
||||||
|
var m_gy = floor(m_ay / _gs);
|
||||||
|
|
||||||
|
var _index = m_gy * col + m_gx;
|
||||||
|
if(_index < pre_amo && _index >= 0)
|
||||||
|
DRAGGING = {
|
||||||
|
type: "Color",
|
||||||
|
data: array_safe_get(preset.palette, _index)
|
||||||
|
}
|
||||||
|
} else if(point_in_rectangle(_m[0], _m[1], ui(10), yy, ww - ui(10), yy + ui(24)))
|
||||||
|
DRAGGING = {
|
||||||
|
type: "Palette",
|
||||||
|
data: preset.palette
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
yy += _height + ui(8);
|
||||||
|
hh += _height + ui(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hh;
|
||||||
|
});
|
||||||
|
|
||||||
|
function drawContent(panel) {
|
||||||
|
PANEL_PADDING
|
||||||
|
PANEL_TITLE
|
||||||
|
|
||||||
|
var px = ui(padding);
|
||||||
|
var py = ui(title_height);
|
||||||
|
var pw = w - ui(padding + padding);
|
||||||
|
var ph = h - ui(title_height + padding);
|
||||||
|
|
||||||
|
draw_sprite_stretched(THEME.ui_panel_bg, !in_dialog, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
|
||||||
|
|
||||||
|
sp_palettes.setActiveFocus(pFOCUS, pHOVER);
|
||||||
|
sp_palettes.draw(px, py, mx - px, my - py);
|
||||||
|
|
||||||
|
var bx = w - ui(32 + 16);
|
||||||
|
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, "Refresh", THEME.refresh, 1, COLORS._main_icon) == 2)
|
||||||
|
presetCollect();
|
||||||
|
|
||||||
|
bx -= ui(32)
|
||||||
|
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, "Change view", THEME.icon_visibility, 1, COLORS._main_icon) == 2)
|
||||||
|
view_mode = (view_mode + 1) % 3;
|
||||||
|
}
|
||||||
|
}
|
11
scripts/panel_palette/panel_palette.yy
Normal file
11
scripts/panel_palette/panel_palette.yy
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"resourceType": "GMScript",
|
||||||
|
"resourceVersion": "1.0",
|
||||||
|
"name": "panel_palette",
|
||||||
|
"isCompatibility": false,
|
||||||
|
"isDnD": false,
|
||||||
|
"parent": {
|
||||||
|
"name": "colors",
|
||||||
|
"path": "folders/panels/colors.yy",
|
||||||
|
},
|
||||||
|
}
|
3
scripts/panel_palette603/panel_palette603.gml
Normal file
3
scripts/panel_palette603/panel_palette603.gml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
function panel_palette603(){
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
function panel_preview_window602(){
|
||||||
|
|
||||||
|
}
|
10
shaders/Shader178/Shader178.fsh
Normal file
10
shaders/Shader178/Shader178.fsh
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
//
|
||||||
|
// Simple passthrough fragment shader
|
||||||
|
//
|
||||||
|
varying vec2 v_vTexcoord;
|
||||||
|
varying vec4 v_vColour;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
|
||||||
|
}
|
19
shaders/Shader178/Shader178.vsh
Normal file
19
shaders/Shader178/Shader178.vsh
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
//
|
||||||
|
// Simple passthrough vertex shader
|
||||||
|
//
|
||||||
|
attribute vec3 in_Position; // (x,y,z)
|
||||||
|
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
|
||||||
|
attribute vec4 in_Colour; // (r,g,b,a)
|
||||||
|
attribute vec2 in_TextureCoord; // (u,v)
|
||||||
|
|
||||||
|
varying vec2 v_vTexcoord;
|
||||||
|
varying vec4 v_vColour;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
|
||||||
|
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
|
||||||
|
|
||||||
|
v_vColour = in_Colour;
|
||||||
|
v_vTexcoord = in_TextureCoord;
|
||||||
|
}
|
10
shaders/sh_color_select_side179/sh_color_select_side179.fsh
Normal file
10
shaders/sh_color_select_side179/sh_color_select_side179.fsh
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
//
|
||||||
|
// Simple passthrough fragment shader
|
||||||
|
//
|
||||||
|
varying vec2 v_vTexcoord;
|
||||||
|
varying vec4 v_vColour;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
|
||||||
|
}
|
19
shaders/sh_color_select_side179/sh_color_select_side179.vsh
Normal file
19
shaders/sh_color_select_side179/sh_color_select_side179.vsh
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
//
|
||||||
|
// Simple passthrough vertex shader
|
||||||
|
//
|
||||||
|
attribute vec3 in_Position; // (x,y,z)
|
||||||
|
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
|
||||||
|
attribute vec4 in_Colour; // (r,g,b,a)
|
||||||
|
attribute vec2 in_TextureCoord; // (u,v)
|
||||||
|
|
||||||
|
varying vec2 v_vTexcoord;
|
||||||
|
varying vec4 v_vColour;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
|
||||||
|
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
|
||||||
|
|
||||||
|
v_vColour = in_Colour;
|
||||||
|
v_vTexcoord = in_TextureCoord;
|
||||||
|
}
|
Loading…
Reference in a new issue