4 * Copyright 2020 Elias Fleckenstein <eliasfleckenstein@web.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 dragonblocks.gui = {};
24 dragonblocks.gui.toggleLayer = function(){
25 dragonblocks.gui.layerShown ? dragonblocks.gui.hideLayer() : dragonblocks.gui.showLayer();
27 dragonblocks.gui.showLayer = dragonblocks.gui.openLayer = function(){
28 dragonblocks.gui.layerShown = true;
29 document.getElementById("dragonblocks.gui.layer").style.visibility = "visible";
31 dragonblocks.gui.hideLayer = dragonblocks.gui.closeLayer = function(){
32 dragonblocks.gui.layerShown = false;
33 document.getElementById("dragonblocks.gui.layer").style.visibility = "hidden";
36 let layer = document.createElement("div");
37 layer.id = "dragonblocks.gui.layer";
38 layer.style.opacity = 0.7;
39 layer.style.position = "fixed";
40 layer.style.width = "100%";
41 layer.style.height = "100%";
42 layer.style.top = "0px";
43 layer.style.left = "0px";
44 layer.style.backgroundColor = "black";
45 layer.style.visibility = "hidden";
46 document.body.appendChild(layer);
48 dragonblocks.gui.Box = class{
49 constructor(properties){
50 this.moveable = false;
51 this.closeable = true;
57 dblib.copy(this, properties);
59 this.id = "dragonblocks.gui.box[" + dragonblocks.getToken() + "]";
62 this.dragging = false;
63 let display = document.createElement("div");
65 display.style.width = "500px";
66 display.style.height = "300px";
67 if(this.size == "big"){
68 display.style.width = "700px";
69 display.style.height = "500px";
71 display.style.position = "fixed";
72 display.style.backgroundColor = "#7E7E7E";
73 display.style.visibility = "hidden";
75 display.style.overflowY = "scroll";
76 let moveField = document.createElement("div");
77 moveField.id = this.id + ".moveField";
78 moveField.style.position = "absolute";
79 moveField.style.left = "0px";
80 moveField.style.top = "0px";
81 moveField.style.width = "30px";
82 moveField.style.height = "30px";
83 if(this.size == "big"){
84 moveField.style.width = "50px";
85 moveField.style.height = "50px";
87 moveField.style.background = dragonblocks.getTexture("move.png");
88 moveField.style.backgroundSize = "cover"
89 moveField.style.cursor = "move";
91 display.appendChild(moveField);
92 let closeField = document.createElement("div");
93 closeField.id = this.id + ".closeField";
94 closeField.style.position = "absolute";
95 closeField.style.right = "0px";
96 closeField.style.top = "0px";
97 closeField.style.width = "30px";
98 closeField.style.height = "30px";
99 if(this.size == "big"){
100 closeField.style.width = "50px";
101 closeField.style.height = "50px";
103 closeField.style.background = dragonblocks.getTexture("close.png");
104 closeField.style.backgroundSize = "cover";
105 closeField.style.cursor = "pointer";
106 closeField.addEventListener("mousedown", _ => {
110 display.appendChild(closeField);
111 display.addEventListener("mousedown", event => {
112 if(event.srcElement.id != moveField.id)
114 self.x = event.clientX;
115 self.y = event.clientY;
116 self.dragging = true;
118 display.addEventListener("mousemove", event => {
121 let display = self.getDisplay();
122 let posX = self.x - event.clientX;
123 let posY = self.y - event.clientY;
124 self.x = event.clientX;
125 self.y = event.clientY;
126 display.style.left = display.offsetLeft - posX + "px";
127 display.style.top = display.offsetTop - posY + "px";
129 addEventListener("mouseup", event => {
130 self.dragging = false;
132 document.body.appendChild(display);
133 dblib.center(this.getDisplay());
134 dblib.centerVertical(this.getDisplay());
137 return document.getElementById(this.id);
140 this.getDisplay().innerHTML = html;
143 this.getDisplay().style.visibility = "visible";
145 dragonblocks.gui.openLayer();
147 dragonblocks.keyHandler.lockAll();
148 this.onopen && this.onopen();
151 this.getDisplay().style.visibility = "hidden";
153 dragonblocks.gui.closeLayer();
155 dragonblocks.keyHandler.unlockAll();
156 this.onclose && this.onclose();
159 return this.getDisplay().appendChild(elem);
162 return this.add(document.createElement(elementname));
165 dragonblocks.gui.createBox = function(properties){
166 return new dragonblocks.gui.Box(properties);