Revert "added resizing of the window"

This commit is contained in:
cantbesure1 2017-11-12 12:23:02 -08:00 committed by GitHub
parent f5aab24567
commit 6d47c7bca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 115 deletions

View File

@ -6,7 +6,7 @@ let win
app.on('ready', () =>
{
win = new BrowserWindow({width: 390, height: 420, backgroundColor:"#000", frame:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
win = new BrowserWindow({width: 390, height: 420, backgroundColor:"#000", frame:false, resizable:false, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
win.loadURL(`file://${__dirname}/sources/index.html`)

View File

@ -1,15 +1,14 @@
body { background:#fff; padding: 5px; font-family: 'input_mono_regular'; -webkit-user-select: none; overflow: hidden;}
body { background:#fff; padding:30px; font-family: 'input_mono_regular'; -webkit-user-select: none;-webkit-app-region: drag; overflow: hidden;}
#wrapper { width: calc(100% - 50px); height: calc(100% - 50px); padding: 25px; background: inherit; -webkit-app-region: drag;}
#dotgrid { margin:0px auto; position:relative; overflow: hidden; padding:10px;-webkit-app-region: no-drag;}
#cursor { width:8px; height:8px; margin-top:-5px; margin-left:-5px; position:absolute; z-index:25; border-radius:5px; border:1px solid black;}
#cursor_coord { font-size:10px; z-index: 10000; margin-left:15px; margin-top:-2px;}
#cursor_coord { font-size:10px; z-index: 10000; margin-left:15px; margin-top:-2px;}
#cursor_coord.left { margin-left:-110px; text-align: right; width:100px; }
#cursor_from { width:4px; height:4px; background:white; margin-top:-3px; margin-left:-3px; position:absolute; z-index:2500; border-radius:10px; left:-100px;border:1px solid black;}
#cursor_to { width:4px; height:4px; background:white; margin-top:-3px; margin-left:-3px; position:absolute; z-index:2500; border-radius:10px; left:-100px; border:1px solid black;}
#cursor_end { width:4px; height:4px; background:white; margin-top:-3px; margin-left:-3px; position:absolute; z-index:2500; border-radius:10px; left:-100px; border:1px solid black;}
#interface { max-width: 295px;margin:0px auto;font-size: 11px;line-height: 30px; text-transform: uppercase; margin-top:20px;-webkit-app-region: no-drag;}
#guide { position: absolute;top: 0px;left: 0px;padding: 10px; width: 300px;height: 300px;}
#guide { position: absolute;top: 30px;left: calc(50vw - 160px);padding: 10px; width: 300px;height: 300px;}
#guide .marker { width:2px; height:2px; position:absolute; margin-top:-1px; margin-left:-1px; border-radius:4px; z-index:50;}
#render { display: none }

View File

@ -20,9 +20,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.element.style.width = this.width;
this.element.style.height = this.height;
this.wrapper = document.createElement("div");
this.wrapper.id = "wrapper";
this.grid_width = this.width/this.grid_x;
this.grid_height = this.height/this.grid_y;
@ -48,15 +45,13 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.segments = [];
this.interface = document.createElement("div");
this.interface.id = "interface";
this.scale = 1
this.install = function()
{
document.body.appendChild(this.wrapper);
this.wrapper.appendChild(this.element);
this.wrapper.appendChild(this.interface);
this.element.appendChild(this.guide.el);
this.wrapper.appendChild(this.render.el);
document.body.appendChild(this.element);
document.body.appendChild(this.interface);
document.body.appendChild(this.guide.el);
document.body.appendChild(this.render.el);
// Cursors
this.cursor = document.createElement("div");
@ -132,10 +127,10 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
var pos = this.position_in_grid(new Pos(e.clientX,e.clientY));
pos = this.position_on_grid(pos);
this.cursor.style.left = Math.floor(-(pos.x-this.grid_width));
this.cursor.style.top = Math.floor(pos.y+this.grid_height);
this.cursor.style.left = -pos.x + 10;
this.cursor.style.top = pos.y + 10;
this.cursor_coord.className = -pos.x > 150 ? "fl left" : "fl"
this.cursor_coord.textContent = parseInt(-pos.x/this.grid_width)+","+parseInt(pos.y/this.grid_height);
this.cursor_coord.textContent = parseInt(-pos.x/10)+","+parseInt(pos.y/10);
}
this.mouse_up = function(e)
@ -146,9 +141,9 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
if(e.altKey){ dotgrid.delete_at(pos); return; }
if(pos.x>0) return;
if(from === null){ this.set_from(pos.scale(1/this.scale)); }
else if(to === null){ this.set_to(pos.scale(1/this.scale)); }
else{ this.set_end(pos.scale(1/this.scale)); }
if(from === null){ this.set_from(pos); }
else if(to === null){ this.set_to(pos); }
else{ this.set_end(pos); }
this.draw();
}
@ -158,22 +153,22 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
{
from = pos;
cursor_from.style.left = Math.floor(-pos.x*this.scale + this.grid_width);
cursor_from.style.top = Math.floor(pos.y*this.scale + this.grid_height);
cursor_from.style.left = -pos.x + 10;
cursor_from.style.top = pos.y + 10;
}
this.set_to = function(pos)
{
cursor_to.style.left = Math.floor(-pos.x*this.scale + this.grid_width);
cursor_to.style.top = Math.floor(pos.y*this.scale + this.grid_height);
cursor_to.style.left = -pos.x + 10;
cursor_to.style.top = pos.y + 10;
to = pos;
}
this.set_end = function(pos)
{
cursor_end.style.left = Math.floor(-pos.x*this.scale + this.grid_width);
cursor_end.style.top = Math.floor(pos.y*this.scale + this.grid_height);
cursor_end.style.left = -pos.x + 10;
cursor_end.style.top = pos.y + 10;
end = pos;
}
@ -247,7 +242,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.draw();
}
this.draw = function(exp = false)
this.draw = function()
{
var d = "";
var prev = "";
@ -263,31 +258,29 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.svg_el.style.height = this.height;
this.svg_el.style.stroke = this.color;
this.svg_el.style.strokeLinecap = this.linecap;
this.svg_el.style.strokeWidth = this.thickness*this.scale;
this.svg_el.style.strokeWidth = this.thickness;
this.svg_el.style.fill = this.fill ? "black" : "none";
//console.log(this.svg_el)
// Draw Mirror
if(this.mirror_index == 1){
this.mirror_path.setAttribute("d",d);
this.mirror_path.setAttribute("transform","translate("+(this.width - (this.offset.x*this.scale))+","+(this.offset.y*this.scale)+"),scale(-1,1)")
this.mirror_path.setAttribute("transform","translate("+(300 - (this.offset.x))+","+(this.offset.y)+"),scale(-1,1)")
}
else if(this.mirror_index == 2){
this.mirror_path.setAttribute("d",d);
this.mirror_path.setAttribute("transform","translate("+((this.offset.x*this.scale))+","+(this.height - (this.offset.y*this.scale))+"),scale(1,-1)")
this.mirror_path.setAttribute("transform","translate("+((this.offset.x))+","+(300 - (this.offset.y))+"),scale(1,-1)")
}
else if(this.mirror_index == 3){
this.mirror_path.setAttribute("d",d);
this.mirror_path.setAttribute("transform","translate("+(this.width -(this.offset.x*this.scale))+","+(this.height - (this.offset.y*this.scale))+"),scale(-1,-1)")
this.mirror_path.setAttribute("transform","translate("+(300 -(this.offset.x))+","+(300 - (this.offset.y))+"),scale(-1,-1)")
}
else{
this.mirror_path.setAttribute("d",'M0,0');
this.mirror_path.setAttribute("transform","")
}
this.offset_el.setAttribute("transform","translate("+(this.offset.x*this.scale)+","+(this.offset.y*this.scale)+")")
this.offset_el.setAttribute("transform","translate("+(this.offset.x)+","+(this.offset.y)+")")
this.render.draw();
this.update_interface();
@ -384,15 +377,10 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.export = function()
{
if(this.segments.length == 0){ return; }
this.scale = 1
this.width = 300
this.height = 300
this.draw()
var svg = this.svg_el.outerHTML
dialog.showSaveDialog((fileName) => {
if (fileName === undefined){ return; }
fs.writeFile(fileName+".svg", svg, (err) => {
fs.writeFile(fileName+".svg", dotgrid.svg_el.outerHTML, (err) => {
if(err){ alert("An error ocurred creating the file "+ err.message); return; }
});
fs.writeFile(fileName+'.png', dotgrid.render.buffer());
@ -449,13 +437,13 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
this.position_in_grid = function(pos)
{
return new Pos((window.innerWidth/2) - (this.width/2) - pos.x,pos.y - (30+10*(this.scale)))
return new Pos((window.innerWidth/2) - (this.width/2) - pos.x,pos.y - 50)
}
this.position_on_grid = function(pos) // rounds the mouse position to the nearest cell, and limits the coords to within the box
{
x = Math.round(pos.x/this.grid_width)*this.grid_width
y = Math.round(pos.y/this.grid_height)*this.grid_height
y = Math.round(pos.y/this.grid_height)*this.grid_height+this.grid_height
off = (x<-this.width || x>0 || y>this.height || y<0)
if(off) { // change position so the cursor will not be seen
x = 50
@ -463,36 +451,6 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y,thickness = 3,lineca
}
return new Pos(x,y);
}
this.resize = function()
{
this.scale = Math.min((window.innerWidth-90)/300,(window.innerHeight-100)/320)
this.width = dotgrid.scale*300
this.height = dotgrid.scale*300
this.element.style.width = this.width
this.element.style.height = this.height
this.element.style.padding = Math.floor(10*this.scale)+"px"
this.svg_el.setAttribute("width",this.width+"px");
this.svg_el.setAttribute("height",this.height+"px");
this.grid_width = dotgrid.width/dotgrid.grid_x;
this.grid_height = dotgrid.height/dotgrid.grid_y;
this.guide.update()
//cursor updates
if(from) {
cursor_from.style.left = Math.floor(-from.x*this.scale + this.grid_width);
cursor_from.style.top = Math.floor(from.y*this.scale + this.grid_height);
}
if(to) {
cursor_to.style.left = Math.floor(-to.x*this.scale + this.grid_width);
cursor_to.style.top = Math.floor(to.y*this.scale + this.grid_height);
}
if(end) {
cursor_end.style.left = Math.floor(-end.x*this.scale + this.grid_width);
cursor_end.style.top = Math.floor(end.y*this.scale + this.grid_height);
}
}
}
window.addEventListener('dragover',function(e)
@ -502,12 +460,6 @@ window.addEventListener('dragover',function(e)
e.dataTransfer.dropEffect = 'copy';
});
window.addEventListener('resize', function(e)
{
dotgrid.resize()
dotgrid.draw()
}, false);
window.addEventListener('drop', function(e)
{
e.preventDefault();

View File

@ -4,29 +4,17 @@ function Guide()
// Guide
this.el.id = "guide";
this.markers;
this.start = function()
{
// Markers
this.markers = JSON.parse("["+"[],".repeat(dotgrid.grid_x)+"[]"+"]")
for (var x = dotgrid.grid_x; x >= 0; x--) {
for (var y = dotgrid.grid_y; y >= 0; y--) {
let marker = document.createElement("div");
var marker = document.createElement("div");
marker.setAttribute("class",(x % dotgrid.block_x == 0 && y % dotgrid.block_y == 0 ? "marker bm" : "marker bl"));
marker.style.left = parseInt(x * dotgrid.grid_width + (dotgrid.grid_width/2)) ;
marker.style.top = parseInt(y * dotgrid.grid_height + (dotgrid.grid_height/2)) ;
marker.style.left = parseInt(x * dotgrid.grid_width + (dotgrid.grid_width/2)) +5;
marker.style.top = parseInt(y * dotgrid.grid_height + (dotgrid.grid_height/2)) +5;
this.el.appendChild(marker);
this.markers[x][y] = marker
}
}
}
this.update = function() // it's less than ideal to reuse this much code, but I couldn't find a way to reuse the function that wouldn't mess with the architecture
{
for (var x = dotgrid.grid_x; x >= 0; x--) {
for (var y = dotgrid.grid_y; y >= 0; y--) {
let marker = this.markers[x][y]
marker.style.left = parseInt(x * dotgrid.grid_width + (dotgrid.grid_width/2) +(5*dotgrid.scale));
marker.style.top = parseInt(y * dotgrid.grid_height + (dotgrid.grid_height/2) +(5*dotgrid.scale));
}
}
}

View File

@ -12,25 +12,25 @@ function Path_Arc(from,to,orientation,end)
var html = ""
if(!prev || (!prev.to && !prev.end)){
html += "M"+this.from.scale(dotgrid.scale)+" ";
html += "M"+this.from+" ";
}
else if(prev){
if(prev.end){
if(!prev.end.is_equal(this.from)){
html += "M"+this.from.scale(dotgrid.scale)+" ";
html += "M"+this.from+" ";
}
}
else if(prev.to){
if(!prev.to.is_equal(this.from)){
html += "M"+this.from.scale(dotgrid.scale)+" ";
html += "M"+this.from+" ";
}
}
}
html += "A"+this.to.sub(this.from).scale(dotgrid.scale)+" 0 "+orientation+" "+this.to.scale(dotgrid.scale)+" ";
html += "A"+this.to.sub(this.from)+" 0 "+orientation+" "+this.to+" ";
if(this.end){
html += "A"+this.end.sub(this.to).scale(dotgrid.scale)+" 0 "+orientation+" "+this.end.scale(dotgrid.scale)+" ";
html += "A"+this.end.sub(this.to)+" 0 "+orientation+" "+this.end+" ";
}
return html

View File

@ -11,21 +11,21 @@ function Path_Bezier(from,to,end)
var html = ""
if(!prev || (!prev.to && !prev.end)){
html += "M"+this.from.scale(dotgrid.scale)+" ";
html += "M"+this.from+" ";
}
else if(prev){
if(prev.end){
if(!prev.end.is_equal(this.from)){
html += "M"+this.from.scale(dotgrid.scale)+" ";
html += "M"+this.from+" ";
}
}
else if(prev.to){
if(!prev.to.is_equal(this.from)){
html += "M"+this.from.scale(dotgrid.scale)+" ";
html += "M"+this.from+" ";
}
}
}
return html += "Q"+this.to.scale(dotgrid.scale)+" "+this.end.scale(dotgrid.scale)+" "
return html += "Q"+this.to+" "+this.end+" "
}
}

View File

@ -11,25 +11,25 @@ function Path_Line(from,to,end = null)
var html = ""
if(!prev || (!prev.to && !prev.end)){
html += "M"+this.from.scale(dotgrid.scale)+" ";
html += "M"+this.from+" ";
}
else if(prev){
if(prev.end){
if(!prev.end.is_equal(this.from.scale(dotgrid.scale))){
html += "M"+this.from.scale(dotgrid.scale)+" ";
if(!prev.end.is_equal(this.from)){
html += "M"+this.from+" ";
}
}
else if(prev.to){
if(!prev.to.is_equal(this.from.scale(dotgrid.scale))){
html += "M"+this.from.scale(dotgrid.scale)+" ";
if(!prev.to.is_equal(this.from)){
html += "M"+this.from+" ";
}
}
}
html += "L"+this.to.scale(dotgrid.scale)+" "
html += "L"+this.to+" "
if(this.end){
html += "L"+this.end.scale(dotgrid.scale)+" "
html += "L"+this.end+" "
}
return html

View File

@ -22,9 +22,4 @@ function Pos(x,y)
{
return Math.abs(pos2.x) == Math.abs(this.x) && Math.abs(pos2.y) == Math.abs(this.y);
}
this.scale = function(a)
{
return new Pos(this.x*a,this.y*a)
}
}