8000 miniPaint/js/gui.js at v3.1 · Mu-L/miniPaint · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
711 lines (648 loc) · 22.1 KB

gui.js

File metadata and controls

711 lines (648 loc) · 22.1 KB
if(is_circle == false){
//hide strict controlls
document.getElementById('strict').style.display = 'none';
}
else{
//show strict controlls
document.getElementById('strict').style.display = 'block';
}
}
};
this.action = function (key) {
DRAW[key]('init', {valid: true});
if (DRAW.active_tool == key)
return false;
//change
if (DRAW.active_tool != '')
document.getElementById(DRAW.active_tool).className = "";
DRAW.active_tool = key;
document.getElementById(key).className = "active trn";
this.show_action_attributes();
return false;
};
this.action_data = function () {
for (var i in DRAW_TOOLS_CONFIG) {
if (DRAW_TOOLS_CONFIG[i].name == DRAW.active_tool)
return DRAW_TOOLS_CONFIG[i];
}
};
/**
* used strings:
* "Fill", "Square", "Circle", "Radial", "Anti aliasing", "Circle", "Strict", "Burn"
*/
this.show_action_attributes = function () {
html = '';
var step = 10;
for (var k in this.action_data().attributes) {
var title = k[0].toUpperCase() + k.slice(1);
title = title.replace("_", " ");
if (this.action_data().attributes[k + "_values"] != undefined)
continue;
if (this.action_data().attributes[k] === true || this.action_data().attributes[k] === false) {
//true / false
if (this.action_data().attributes[k] == true)
html += '<div 1)" style="background-color:#5680c1;" class="attribute-area trn" id="' + k + '">' + title + '</div>';
else
html += '<div 0)" class="attribute-area trn" id="' + k + '">' + title + '</div>';
}
else if (typeof GUI.action_data().attributes[k] == 'object') {
//drop down select
html += '<select style="font-size:11px;margin-bottom:10px;" id="' + k + '">';
for (var j in GUI.action_data().attributes[k]) {
var sel = '';
var key = k.replace("_values", "");
if (GUI.action_data().attributes[key] == GUI.action_data().attributes[k][j])
sel = 'selected="selected"';
html += '<option class="trn" ' + sel + ' name="' + GUI.action_data().attributes[k][j] + '" data-value="'+GUI.action_data().attributes[k][j]+'">' + GUI.action_data().attributes[k][j] + '</option>';
}
html += '</select>';
}
else if (GUI.action_data().attributes[k][0] == '#') {
//color
html += '<table style="width:100%;">'; //table for 100% width
html += '<tr>';
html += '<td style="font-weight:bold;width:45px;">' + title + ':</td>';
html += '<td><input type="color" id="' + k + '" value="' + GUI.action_data().attributes[k] + '" /></td>';
html += '</tr>';
html += '</table>';
}
else {
//numbers
html += '<div id="' + k + '_container">';
html += '<table style="width:100%;">'; //table for 100% width
html += '<tr>';
html += '<td style="font-weight:bold;padding-right:2px;white-space:nowrap;" class="trn">' + title + ':</td>';
html += '<td><input type="number" id="' + k + '" value="' + GUI.action_data().attributes[k] + '" /></td>';
html += '</tr>';
html += '</table>';
html += '<div style="float:left;width:32px;" ' + (step) + ')" class="attribute-area" id="' + k + '">+</div>';
html += '<div style="margin-left:48px;margin-bottom:15px;" ' + (-step) + ')" class="attribute-area" id="' + k + '">-</div>';
html += '</div>';
}
}
document.getElementById("action_attributes").innerHTML = html;
//retranslate
HELP.help_translate(LANG);
};
this.set_color = function (object) {
if (HELPER.chech_input_color_support('main_color') == true && object.id == 'main_color')
COLOR = object.value;
else
COLOR = HELPER.rgb2hex_all(object.style.backgroundColor);
COLOR_copy = COLOR;
if (HELPER.chech_input_color_support('main_color') == true)
document.getElementById("main_color").value = COLOR; //supported
else
document.getElementById("main_color_alt").style.backgroundColor = COLOR; //not supported
document.getElementById("color_hex").value = COLOR;
var colors = HELPER.hex2rgb(COLOR);
document.getElementById("rgb_r").value = colors.r;
document.getElementById("rgb_g").value = colors.g;
document.getElementById("rgb_b").value = colors.b;
};
this.set_color_manual = function (event) {
var object = event.target;
if (object.value.length == 6 && object.value[0] != '#') {
COLOR = '#' + object.value;
this.sync_colors();
}
if (object.value.length == 7) {
COLOR = object.value;
this.sync_colors();
}
else if (object.value.length > 7)
object.value = COLOR;
};
this.set_color_rgb = function (object, c) {
var colors = HELPER.hex2rgb(COLOR);
if (object.value.length > 3) {
object.value = colors[c];
}
else if (object.value.length > 0) {
value = object.value;
value = parseInt(value);
if (isNaN(value) || value != object.value || value > 255 || value < 0) {
object.value = colors[c];
return false;
}
COLOR = "#" + ("000000" + HELPER.rgbToHex(document.getElementById("rgb_r").value, document.getElementById("rgb_g").value, document.getElementById("rgb_b").value)).slice(-6);
ALPHA = document.getElementById("rgb_a").value;
document.getElementById("rgb_a").value = ALPHA;
this.sync_colors();
}
};
this.sync_colors = function () {
document.getElementById("color_hex").value = COLOR;
if (HELPER.chech_input_color_support('main_color') == true)
document.getElementById("main_color").value = COLOR; //supported
else
document.getElementById("main_color_alt").style.backgroundColor = COLOR; //not supported
var colors = HELPER.hex2rgb(COLOR);
document.getElementById("rgb_r").value = colors.r;
document.getElementById("rgb_g").value = colors.g;
document.getElementById("rgb_b").value = colors.b;
};
this.toggle_color_select = function () {
if (POP.active == false) {
POP.add({
title: 'Color:',
function: function () {
COLOR_copy = COLOR;
var html = '<canvas style="position:relative;margin-bottom:5px;" id="c_all" width="300" height="300"></canvas>';
html += '<table>';
html += '<tr>';
html += ' <td><b>Luminosity:</b></td>';
html += ' <td><input id="lum_ranger" type="range" value="0" min="-255" max="255" step="1"></td>';
html += ' <td style="padding-left:10px;width:30px;" id="lum_preview">0</td>';
html += '</tr>';
html += '<tr>';
html += ' <td><b>Alpha:</b></td>';
html += ' <td><input type="range" value="' + ALPHA + '" min="0" max="255" step="1"></td>';
html += ' <td style="padding-left:10px;" id="alpha_preview">' + ALPHA + '</td></tr>';
html += '</tr>';
html += '</table>';
return html;
}
});
POP.show(
'Select color',
function (user_response) {
var param1 = parseInt(user_response.param1);
},
undefined,
this.toggle_color_select_onload
);
}
else{
POP.hide();
}
};
this.change_lum = function (lumi) {
lumi = parseInt(lumi);
var c3 = HELPER.hex2rgb(COLOR_copy);
c3.r += lumi;
c3.g += lumi;
c3.b += lumi;
if (c3.r < 0)
c3.r = 0;
if (c3.g < 0)
c3.g = 0;
if (c3.b < 0)
c3.b = 0;
if (c3.r > 255)
c3.r = 255;
if (c3.g > 255)
c3.g = 255;
if (c3.b > 255)
c3.b = 255;
COLOR = "#" + ("000000" + HELPER.rgbToHex(c3.r, c3.g, c3.b)).slice(-6);
this.sync_colors();
};
this.change_alpha = function (value) {
ALPHA = parseInt(value);
document.getElementById("rgb_a").value = ALPHA;
};
this.toggle_color_select_onload = function () {
var img = new Image();
img. () {
document.getElementById("c_all").getContext("2d").drawImage(img, 0, 0);
document.getElementById("c_all"). (event) {
if (event.offsetX) {
mouse_x = event.offsetX;
mouse_y = event.offsetY;
}
else if (event.layerX) {
mouse_x = event.layerX;
mouse_y = event.layerY;
}
var c = document.getElementById("c_all").getContext("2d").getImageData(mouse_x, mouse_y, 1, 1).data;
COLOR = "#" + ("000000" + HELPER.rgbToHex(c[0], c[1], c[2])).slice(-6);
this.sync_colors();
COLOR_copy = COLOR;
document.getElementById("lum_ranger").value = 0;
};
};
img.src = 'img/colorwheel.png';
};
this.draw_selected_area = function (no_resize) {
if (DRAW.select_data == false)
return false;
//draw area
canvas_front.clearRect(0, 0, WIDTH, HEIGHT);
var x = DRAW.select_data.x;
var y = DRAW.select_data.y;
var w = DRAW.select_data.w;
var h = DRAW.select_data.h;
if (t 5988 his.ZOOM != 100) {
x = Math.round(x);
y = Math.round(y);
w = Math.round(w);
h = Math.round(h);
}
//fill
canvas_front.fillStyle = "rgba(0, 255, 0, 0.3)";
canvas_front.fillRect(x, y, w, h);
if (this.ZOOM <= 100) {
//borders
canvas_front.strokeStyle = "rgba(0, 255, 0, 1)";
canvas_front.lineWidth = 1;
canvas_front.strokeRect(x + 0.5, y + 0.5, w, h);
}
if (no_resize == true)
return true;
//draw carners
square(x, y, 0, 0);
square(x + w, y, -1, 0);
square(x, y + h, 0, -1);
square(x + w, y + h, -1, -1);
//draw centers
square(x + w / 2, y, 0, 0);
square(x, y + h / 2, 0, 0);
square(x + w / 2, y + h, 0, -1);
square(x + w, y + h / 2, -1, 0);
function square(x, y, mx, my) {
var sr_size = Math.ceil(EVENTS.sr_size / GUI.ZOOM * 100);
x = Math.round(x);
y = Math.round(y);
canvas_front.beginPath();
canvas_front.rect(x + mx * Math.round(sr_size), y + my * Math.round(sr_size), sr_size, sr_size);
canvas_front.fillStyle = "#0000ff";
canvas_front.fill();
}
};
this.toggle = function(query){
document.querySelector(query).classList.toggle("active");
};
}
0