aboutsummaryrefslogtreecommitdiff
path: root/window.lua
blob: 53a4ac20f8cdb6cc819c2d4b7843b79abd4802ae (plain)
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
263
264
265
266
267
268
269
270
271
function drawWindow(id)
  if win[id].update == true then
    love.graphics.setCanvas(win[id].cvs)
    love.graphics.setColor(192, 192, 192)
    love.graphics.rectangle("fill", 0, 0, win[id].w, win[id].h) --Box
    love.graphics.setLineWidth(4)
    love.graphics.setColor(220, 220, 220)
    love.graphics.line(0, win[id].y+win[id].h, 0, 0, 0+win[id].w, 0) --BoxLight
    love.graphics.setColor(150,150,150)
    love.graphics.line(0, 0+win[id].h, 0+win[id].w, 0+win[id].h, 0+win[id].w, 0) --BoxShadow
    love.graphics.setColor(256,256,256)
    love.graphics.draw(window.bar, 0+3, 0+3, 0, (win[id].w-7)/643, 1) --Blue Bar
    love.graphics.draw(window.x, 0+win[id].w-22, 5)
    love.graphics.draw(window.min, 0+win[id].w-40, 0+5) --Minimize Button
    love.graphics.setColor(220, 220, 220)
    love.graphics.print(win[id].title, 0+6, 0+9) --Title
    if id == 4 then
      drawAntivirus(win[id].x, win[id].y, win[id].hover)
    end
    love.graphics.setCanvas()
    win[id].update = false
  end
  if(sys.mouse.x >= win[id].x and sys.mouse.x <= win[id].x+win[id].w
  and sys.mouse.y >= win[id].y and sys.mouse.y <= win[id].y+win[id].h and win[id].ex == false) then
    win[id].hov = true
    winHover = true
  else
    win[id].hov = false
  end
  if layer[1] ~= 0 and win[id].ex == false then
    if win[id].layer ~= 1 and win[layer[1]].hov == true then
      win[id].hover = false
    elseif win[id].layer ~= 1 and win[id].layer ~= 2 and layer[1] ~= 0 and layer[2] ~= 0 then
      if win[layer[1]].hov == true or win[layer[2]].hov == true then
        win[id].hover = false
      else
        win[id].hover = true
      end
    elseif win[id].hov == false then
      win[id].hover = false
    else
      win[id].hover = true
    end
  end
  if win[id].hov == false then
    win[id].hover = false
  end
  if sys.mouse.y >= sys.h-panel.thick then
    win[id].hover = false
  end
  if win[id].ex == true then
    win[id].hover = false
  end
  if(sys.mouse.p.x >= win[id].x and sys.mouse.p.x <= win[id].x+win[id].w
  and sys.mouse.p.y >= win[id].y and sys.mouse.p.y <= win[id].y+win[id].h) then
  else
    win[id].hover = false
  end
  if win[id].hover == true and sys.mouse.p.p == true and sys.mouse.drag == false then
    layer.sentToFront = id
  end
  if(sys.mouse.p.p == true and sys.mouse.p.x >= win[id].x+2 and sys.mouse.p.x <= (win[id].x+2)+(win[id].w-44)
  and sys.mouse.p.y >= win[id].y+2 and sys.mouse.p.y <= win[id].y+22 and win[id].hover == true) then
    sys.mouse.drag = true
  end
  if sys.mouse.p.p == false then
    sys.mouse.drag = false
    win[id].px = win[id].x
    win[id].py = win[id].y
  end
  if sys.mouse.drag == true and win[id].min == false and win[id].ex == false and layer[1] == id then
    win[id].x = win[id].px + (sys.mouse.x - sys.mouse.p.x)
    win[id].y = win[id].py + (sys.mouse.y - sys.mouse.p.y)
  end
  if (sys.mouse.p.p == true and sys.mouse.p.x >= win[id].x+win[id].w-22 and sys.mouse.p.x <= (win[id].x+win[id].w-22)+16 and win[id].ex == false
  and sys.mouse.drag == false and sys.mouse.p.y >= win[id].y+5 and sys.mouse.p.y <= (win[id].y+5)+16 and win[id].hover == true) then
    win[id].ex = true
  end
  if win[id].ex == true and win[id].s ~= 0 then
    win[id].s = win[id].s - 0.2
  elseif win[id].ex == false and win[id].s ~= 0 then
    win[id].s = win[id].s + 0.2
  end
  if win[id].s <= 0 then
    win[id].s = 0
  elseif win[id].s >= 1 then
    win[id].s = 1
  end
  if (win[id].min == false and sys.mouse.p.p == true and sys.mouse.p.x >= win[id].x+win[id].w-40
  and sys.mouse.p.x <= (win[id].x+win[id].w-40)+16 and sys.mouse.drag == false and sys.mouse.p.y >= win[id].y+5
  and sys.mouse.p.y <= (win[id].y+5)+16 and win[id].hover == true) then
    win[id].min = true
  end
  if win[id].min == true and win[id].miny < minim then
    win[id].y = win[id].y + 150
    win[id].miny = win[id].miny + 150
  end
  if win[id].miny > minim then
    win[id].miny = minim
  end
  if win[id].min == false and win[id].miny > 0 then
    win[id].y = win[id].y - 150
    win[id].miny = win[id].miny - 150
  end
  if win[id].miny < 0 then
    win[id].miny = 0
  end
  if id == 4 then
    updateAntivirus()
  end
  love.graphics.setColor(255,255,255)
end
function orderWindows()
  if layer.sentToFront ~= 0 and layer[1] ~= layer.sentToFront then
    if win[layer.sentToFront].oldlayer == 2 then
        layer[2] = layer[1]
        layer[1] = id
      elseif win[layer.sentToFront].oldlayer == 3 then
        layer[3] = layer[2]
        layer[2] = layer[1]
        layer[1] = id
      elseif win[layer.sentToFront].oldlayer == 4 then
        layer[4] = layer[3]
        layer[3] = layer[2]
        layer[2] = layer[1]
        layer[1] = id
      elseif win[layer.sentToFront].oldlayer == 5 then
        layer[5] = layer[4]
        layer[4] = layer[3]
        layer[3] = layer[2]
        layer[2] = layer[1]
        layer[1] = id
      elseif win[layer.sentToFront].oldlayer == 6 then
        layer[6] = layer[5]
        layer[5] = layer[4]
        layer[4] = layer[3]
        layer[3] = layer[2]
        layer[2] = layer[1]
        layer[1] = id
      else
        layer[7] = layer[6]
        layer[6] = layer[5]
        layer[5] = layer[4]
        layer[4] = layer[3]
        layer[3] = layer[2]
        layer[2] = layer[1]
        layer[1] = id
      end
    layer[1] = layer.sentToFront
    win[layer.sentToFront].oldlayer = win[layer.sentToFront].layer
    win[layer.sentToFront].layer = 1
    layer.sentToFront = 0
  end
  closeWindow(1)
  closeWindow(2)
  closeWindow(3)
  closeWindow(4)
  closeWindow(5)
  closeWindow(6)
  if layer[6] == 0 and layer[7] ~= 0 then
    layer[6] = layer[7]
    layer[7] = 0
  end
  if layer[5] == 0 and layer[6] ~= 0 then
    layer[5] = layer[6]
    layer[6] = 0
  end
  if layer[4] == 0 and layer[5] ~= 0 then
    layer[4] = layer[5]
    layer[5] = 0
  end
  if layer[3] == 0 and layer[4] ~= 0 then
    layer[3] = layer[4]
    layer[4] = 0
  end
  if layer[2] == 0 and layer[3] ~= 0 then
    layer[2] = layer[3]
    layer[3] = 0
  end
  if layer[1] == 0 and layer[2] ~= 0 then
    layer[1] = layer[2]
    layer[2] = 0
  end
  setWindow(6)
  setWindow(5)
  setWindow(4)
  setWindow(3)
  setWindow(2)
  setWindow(1)
  setPanel(1)
  setPanel(2)
  setPanel(3)
  setPanel(4)
  setPanel(5)
  setPanel(6)
  drawWindow(1)
  drawWindow(2)
  drawWindow(3)
  drawWindow(4)
  drawWindow(5)
  drawWindow(6)
end
function setWindow(id)
  if layer[id] ~= 0 then
    win[layer[id]].oldlayer = win[layer[id]].layer
    win[layer[id]].layer = id
  end
end
function setPanel(id)
  if win[id].ex == false then
    if panel.b[1] == 0 then
     panel.b[1] = id
   elseif panel.b[2] == 0 and panel.b[1] ~= id then
     panel.b[2] = id
   elseif panel.b[3] == 0 and panel.b[1] ~= id and panel.b[2] ~= id then
     panel.b[3] = id
   elseif (panel.b[4] == 0 and panel.b[1] ~= id and panel.b[2] ~= id
   and panel.b[3] ~= id) then
     panel.b[4] = id
   elseif (panel.b[5] == 0 and panel.b[1] ~= id and panel.b[2] ~= id
   and panel.b[3] ~= id and panel.b[4] ~= id) then
     panel.b[5] = id
   elseif (panel.b[6] == 0 and panel.b[1] ~= id and panel.b[2] ~= id
   and panel.b[3] ~= id and panel.b[4] ~= id and panel.b[5] ~= id) then
     panel.b[6] = id
   end
 end
 if win[id].ex == true then
   if panel.b[1] == id then
      panel.b[1] = panel.b[2]
      panel.b[2] = panel.b[3]
      panel.b[3] = panel.b[4]
      panel.b[4] = panel.b[5]
      panel.b[5] = panel.b[6]
      panel.b[6] = panel.b[7]
    elseif panel.b[2] == id then
      panel.b[2] = panel.b[3]
      panel.b[3] = panel.b[4]
      panel.b[4] = panel.b[5]
      panel.b[5] = panel.b[6]
      panel.b[6] = panel.b[7]
    elseif panel.b[3] == id then
      panel.b[3] = panel.b[4]
      panel.b[4] = panel.b[5]
      panel.b[5] = panel.b[6]
      panel.b[6] = panel.b[7]
    elseif panel.b[4] == id then
      panel.b[4] = panel.b[5]
      panel.b[5] = panel.b[6]
      panel.b[6] = panel.b[7]
    elseif panel.b[5] == id then
      panel.b[5] = panel.b[6]
      panel.b[6] = panel.b[7]
    elseif panel.b[6] == id then
      panel.b[6] = panel.b[7]
    end
  end
end
function closeWindow(id)
  if win[id].ex == true and win[id].s == 0 then
    win[id].exit = true
    win[id].oldlayer = win[id].layer
  else
    win[id].exit = false
  end
  if win[id].layer ~= 0 and win[id].exit == true then
    layer[win[id].layer] = 0
    win[id].oldlayer = win[id].layer
    win[id].layer = 0
  end
end