-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
262 lines (219 loc) · 6.75 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<html>
<head>
<title>blank</title>
<link rel="stylesheet" type="text/css" href="stylish.css">
</head>
<body>
<canvas width="1366" height="768" id="mainCanvas"></canvas>
<script>
//Canvas Setup
var canvas = document.getElementById("mainCanvas");
var ctx = canvas.getContext("2d");
var lastRender = 0;
//Window Variables
var windowX = 10;
var windowY = 10;
var anchorX = 0;
var anchorY = 0;
var moving = false;
//Mouse Variables
var cursorX = 0;
var cursorY = 0;
var mouseDown = false;
//Populate Inventory
var rows = 7;
var columns = 5;
var itemX = windowX + 15;
var itemY = windowY + 50;
var items = [];
for (var i = 0; i < rows; i++)
{
items.push([]);
for (var j = 0; j < columns; j++)
{
var item = {
x: itemX + (55 * j),
y: itemY + (55 * i),
item: "fanta-and-spirit.png"
};
items[i].push(item);
}
}
/* CORE LOOP */
function update(progress)
{
titleBar();
}
function draw()
{
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawWindow();
drawItems();
drawText();
}
function loop(timestamp)
{
var lastRender = timestamp;
var progress = timestamp - lastRender;
update(progress);
draw();
window.requestAnimationFrame(loop);
}
/* END CORE LOOP */
//Draw Main Window
function drawWindow()
{
//Background
var grad = ctx.createLinearGradient(0, windowY, 0, windowY + 100);
grad.addColorStop(0, "#AAA");
grad.addColorStop(.02, "#555");
grad.addColorStop(1, "#252525");
ctx.fillStyle = grad;
roundRect(windowX, windowY, 300, 470, 8, true, true);
//Drop Shadow
ctx.shadowColor = "black";
ctx.shadowBlur = 12;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
ctx.fill();
ctx.shadowBlur = 0;
}
//Draw Items
function drawItems()
{
for (var i = 0; i < items.length; i++)
{
for (var j = 0; j < items[i].length; j++)
{
//Set up the item to be drawn
var currentItem = items[i][j];
currentItem.x = windowX + 15 + (55 * j);
currentItem.y = windowY + 40 + (55 * i);
//Create the item's image
var img = new Image();
img.src = currentItem.item;
//Gradient creation
var grad = ctx.createLinearGradient(0, currentItem.y - 40, 0, currentItem.y + 15);
if (cursorX > currentItem.x && cursorX < currentItem.x + 50 && cursorY > currentItem.y && cursorY < currentItem.y + 50)
{
canvas.style.cursor = "pointer";
grad.addColorStop(0, "white");
grad.addColorStop(1, "#888");
}
else
{
canvas.style.cursor = "auto";
grad.addColorStop(0, "white");
grad.addColorStop(1, "#666");
}
ctx.fillStyle = grad;
//Draw the items
roundRect(currentItem.x, currentItem.y, 50, 50, 8, true, true);
ctx.drawImage(img, currentItem.x + 2, currentItem.y + 2, 46, 46);
}
}
}
//Draw Text
function drawText()
{
//Drop Shadows
ctx.shadowColor = "black";
ctx.shadowBlur = 3;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 1;
ctx.fill();
//Title
ctx.font = "20px Times New Roman";
ctx.fillStyle = "#CCC";
ctx.fillText("Inventory", windowX + 7, windowY + 24);
//Close Button
ctx.font = "20px Times New Roman";
ctx.fillStyle = "#ff9b44";
ctx.fillText("X", windowX + 280, windowY + 24);
//Numbers
ctx.shadowColor = "yellow";
ctx.shadowBlur = 2;
ctx.shadowOffsetY = 0;
ctx.font = "20px Times New Roman";
ctx.fillStyle = "white";
ctx.fillText("34/35", windowX + 236, windowY + 440);
ctx.shadowColor = "black";
ctx.shadowBlur = 0;
}
//Rounded Corners
function roundRect(x, y, width, height, radius, fill, stroke)
{
var radius = {tl: radius, tr: radius, br: radius, bl: radius};
ctx.beginPath();
ctx.moveTo(x + radius.tl, y);
ctx.lineTo(x + width - radius.tr, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius.tr);
ctx.lineTo(x + width, y + height - radius.br);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius.br, y + height);
ctx.lineTo(x + radius.bl, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius.bl);
ctx.lineTo(x, y + radius.tl);
ctx.quadraticCurveTo(x, y, x + radius.tl, y);
ctx.closePath();
if (fill)
ctx.fill();
if (stroke)
ctx.stroke();
}
//Titlebar Functionality
function titleBar()
{
titleBarBounds = {
left: windowX,
right: windowX + 300,
top: windowY,
bottom: windowY + 34
};
if (!moving)
{
if (cursorX > titleBarBounds.left && cursorX < titleBarBounds.right && cursorY > titleBarBounds.top && cursorY < titleBarBounds.bottom)
{
canvas.style.cursor = "pointer";
if (mouseDown)
{
anchorX = cursorX - windowX;
anchorY = cursorY - windowY;
moving = true;
}
}
else
canvas.style.cursor = "auto";
}
else
{
if (mouseDown)
{
canvas.style.cursor = "all-scroll"
windowX = cursorX - anchorX;
windowY = cursorY - anchorY;
}
else
moving = false;
}
}
//Mouse Down
canvas.addEventListener("mousedown", function(evt)
{
mouseDown = true;
});
//Mouse Up
canvas.addEventListener("mouseup", function(evt)
{
mouseDown = false;
});
//Mouse Movement
canvas.addEventListener("mousemove", function(evt)
{
cursorX = evt.clientX;
cursorY = evt.clientY;
});
window.requestAnimationFrame(loop);
</script>
</body>
</html>