-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.lua
52 lines (44 loc) · 1.67 KB
/
utils.lua
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
function dxDrawLinedRectangle( x, y, width, height, color, _width, postGUI )
_width = _width or 1
dxDrawLine ( x, y, x+width, y, color, _width, postGUI ) -- Top
dxDrawLine ( x, y, x, y+height, color, _width, postGUI ) -- Left
dxDrawLine ( x, y+height, x+width, y+height, color, _width, postGUI ) -- Bottom
return dxDrawLine ( x+width, y, x+width, y+height, color, _width, postGUI ) -- Right
end
function isMouseInPosition ( x, y, width, height )
if ( not isCursorShowing( ) ) then
return false
end
local sx, sy = guiGetScreenSize ( )
local cx, cy = getCursorPosition ( )
local cx, cy = ( cx * sx ), ( cy * sy )
if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
return true
else
return false
end
end
function rgb2hex(r,g,b,s) -- edit by FileEX
local hex_table = {[10] = 'A',[11] = 'B',[12] = 'C',[13] = 'D',[14] = 'E',[15] = 'F'}
local r1 = math.floor(r / 16)
local r2 = r - (16 * r1)
local g1 = math.floor(g / 16)
local g2 = g - (16 * g1)
local b1 = math.floor(b / 16)
local b2 = b - (16 * b1)
if r1 > 9 then r1 = hex_table[r1] end
if r2 > 9 then r2 = hex_table[r2] end
if g1 > 9 then g1 = hex_table[g1] end
if g2 > 9 then g2 = hex_table[g2] end
if b1 > 9 then b1 = hex_table[b1] end
if b2 > 9 then b2 = hex_table[b2] end
if s then
return "0xFF" .. r1 .. r2 .. g1 .. g2 .. b1 .. b2;
else
return tonumber('0xFF' .. r1 .. r2 .. g1 .. g2 .. b1 .. b2);
end
end
function hex2rgba(hex) -- FileEX
hex = hex:gsub("0x","");
return tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)), tonumber("0x"..hex:sub(7,8)), tonumber('0x'..hex:sub(1,2));
end