-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnconvert.lua
More file actions
201 lines (182 loc) · 6.03 KB
/
Copy pathnconvert.lua
File metadata and controls
201 lines (182 loc) · 6.03 KB
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
local screen = platform.window
local w = screen:width()
title = "Unit:" --title
unit = "MiB" --unit (default MiB)
unit_count = 3
input = "" --input
noinputmsg = "Please enter a value"
answer={}
answer[1] = "" --answer 1
answer[2] = "" --answer 2
answer[3] = "" --answer 3
answer[4] = "" --answer 4
noinput = ""
function on.paint(gc)
local title_width = gc:getStringWidth(title)
local unit_width = gc:getStringWidth(unit)
gc:drawString(title,((w/2) - (title_width / 2)), 5, "top") --title
gc:setFont("sansserif", "b", 10)
gc:drawString(unit,((w/2) - (unit_width/2)),40) --unit
gc:setFont("sansserif", "r", 10)
if input ~= "" then
local input_width = gc:getStringWidth(input)
gc:drawString(input,((w/2) - (input_width/2)),63) --input
gc:setPen("thin","smooth")
if string.len(input) <= 4 then
gc:drawRect(((w/2) - 20), 45, 40, 20)
else
gc:drawRect((((w/2) - (input_width/2) - 5)), 45, (input_width + 10), 20)
end
else
if noinput == noinputmsg then
gc:setColorRGB(255,0,0)
gc:setPen("medium","dashed")
gc:drawRect(((w/2) - 20), 45, 40, 20)
else
gc:setColorRGB(0,0,0)
gc:setPen("thin","dashed")
gc:drawRect(((w/2) - 20), 45, 40, 20)
end
end
if answer[1] ~= "" then
local answer_1_width = gc:getStringWidth(answer[1])
local answer_2_width = gc:getStringWidth(answer[2])
local answer_3_width = gc:getStringWidth(answer[3])
local answer_4_width = gc:getStringWidth(answer[4])
gc:setFont("sansserif", "b", 12)
gc:setColorRGB(0,0,255)
gc:drawString(answer[1],((w/2) - (answer_1_width/2) - 10),100)
gc:drawString(answer[2],((w/2) - (answer_2_width/2) - 10),120)
gc:drawString(answer[3],((w/2) - (answer_3_width/2) - 10),140)
gc:drawString(answer[4],((w/2) - (answer_4_width/2) - 10),160)
gc:setFont("sansserif", "r", 10)
gc:setColorRGB(0,0,0)
end
if noinput == noinputmsg then --noinput
local noinput_width = gc:getStringWidth(noinputmsg)
gc:setFont("sansserif", "b", 12)
gc:setColorRGB(255,0,0)
gc:drawString(noinputmsg,((w/2)-(noinput_width/2)-15),100)
gc:setFont("sansserif", "r", 10)
gc:setColorRGB(0,0,0)
end
--explanation
local change_width = gc:getStringWidth("[<->] Change Unit")
gc:drawString("[<->] Change Unit",((w/2) - (change_width/2)),200)
gc:drawString("[Tab] Reset",5,200)
gc:drawString("[Enter] Calc",(w - (5 + 69)),200)
end
function on.charIn(char) --value input
if string.find(char, '%d') == 1 then
if answer[1] ~= "" then --reset answers, if new input appears after calc
answer[1] = ""
answer[2] = ""
answer[3] = ""
answer[4] = ""
input = input..char
noinput = ""
else
input = input..char
noinput = ""
end
end
screen:invalidate()
end
function on.backspaceKey()
input = string.usub(input,0,-2)
screen:invalidate()
end
function on.enterKey() --calculation
if input ~= "" then
if unit == "GiB" then
answer[1] = "MiB: "..(input * 1024)
answer[2] = "KiB: "..(input * 1024 * 1024)
answer[3] = "Bytes: "..(input * 1024 * 1024 * 1024)
answer[4] = "TiB:"..(input / 1024)
end
if unit == "MiB" then
answer[1] = "GiB: "..(input / 1024) --MiB to GiB
answer[2] = "KiB: "..(input * 1024) --MiB to KiB
answer[3] = "Bytes: "..(input * 1024 * 1024) -- MiB to Bytes
answer[4] = "TiB: "..((input / 1024) / 1024) --MiB to TiB
end
if unit == "KiB" then
answer[1] = "GiB: "..((input / 1024) / 1024) --KiB to GiB
answer[2] = "MiB: "..(input / 1024) --KiB to MiB
answer[3] = "Bytes: "..(input * 1024) -- KiB to Bytes
answer[4] = "TiB: "..(((input / 1024) / 1024) / 1024) --KiB to TiB
end
if unit == "Bytes" then
answer[1] = "GiB: "..(((input / 1024) / 1024) / 1024) --Bytes to GiB
answer[2] = "MiB: "..((input / 1024) / 1024) --Bytes to MiB
answer[3] = "KiB: "..(input / 1024) --Bytes to KiB
answer[4] = "TiB: "..((((input / 10124) / 1024) / 1024) / 1024) --Bytes to TiB
end
if unit == "TiB" then
answer[1] = "GiB: "..(input * 1024) --TiB to GiB
answer[2] = "MiB: "..(input * 1024 * 1024) --TiB to MiB
answer[3] = "KiB: "..(input * 1024 * 1024 * 1024) --TiB to KiB
answer[4] = "Bytes: "..(input * 1024 * 1024 * 1024 * 1024) --TiB to Bytes
end
else
noinput = noinput..noinputmsg
end
screen:invalidate()
end
function on.arrowRight()
if unit_count < 5 then
unit_count = (unit_count + 1)
else
unit_count = 1
end
if unit_count == 1 then
unit = "TiB"
end
if unit_count == 2 then
unit = "GiB"
end
if unit_count == 3 then
unit = "MiB"
end
if unit_count == 4 then
unit = "KiB"
end
if unit_count == 5 then
unit = "Bytes"
end
screen:invalidate()
end
function on.arrowLeft()
if unit_count > 1 then
unit_count = (unit_count - 1)
else
unit_count = 5
end
if unit_count == 1 then
unit = "TiB"
end
if unit_count == 2 then
unit = "GiB"
end
if unit_count == 3 then
unit = "MiB"
end
if unit_count == 4 then
unit = "KiB"
end
if unit_count == 5 then
unit = "Bytes"
end
screen:invalidate()
end
function on.tabKey() --reset
input = ""
noinput = ""
answer[1] = ""
answer[2] = ""
answer[3] = ""
answer[4] = ""
unit = "MiB"
unit_count = 3
screen:invalidate()
end