-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrectangle.lua
More file actions
55 lines (48 loc) · 2.57 KB
/
Copy pathrectangle.lua
File metadata and controls
55 lines (48 loc) · 2.57 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
local sx, sy = guiGetScreenSize()
local shader = dxCreateShader('rectangle.fx')
dxSetShaderValue(shader, 'resolution', {sx, sy})
local function __A(a)
if a == nil then return 1.0 end
if a <= 1 then return a end
if a <= 100 then return a / 100 end
return a / 255
end
function drawRectangle(x, y, w, h, settings)
if not shader then return false end
settings = settings or {}
local fill = settings['fill'] or {}
local border = settings['border'] or {}
local gradient = settings['gradient'] or {}
local color = fill['color'] or {255, 255, 255, 255}
local color_border = border['color'] or {0, 0, 0, 0}
local color_progress = border['progress_color'] or color_border
local direction = tostring(gradient['direction'] or 'none'):lower()
local type = direction == 'left' and 1 or direction == 'right' and 2 or direction == 'top' and 3 or direction == 'bottom' and 4 or 0
dxSetShaderValue(shader, "size", {w, h})
dxSetShaderValue(shader, "fillcolor", {color[1]/255, color[2]/255, color[3]/255, (color[4] or 255)/255})
dxSetShaderValue(shader, "border_radius", fill['radius'] or 0)
dxSetShaderValue(shader, "border_width", border['size'] or 0)
dxSetShaderValue(shader, "border_color", {color_border[1]/255, color_border[2]/255, color_border[3]/255, (color_border[4] or 255)/255})
dxSetShaderValue(shader, "progress", (border['progress'] or 0)/100)
dxSetShaderValue(shader, "progress_color", {color_progress[1]/255, color_progress[2]/255, color_progress[3]/255, (color_progress[4] or 255)/255})
dxSetShaderValue(shader, "gradient_alpha", {__A(gradient['alpha_start']), __A(gradient['alpha_end'])})
dxSetShaderValue(shader, "gradient_type", type)
dxDrawImage(-(sx - w)/2 + x, -(sy - h)/2 + y, sx, sy, shader)
return true
end
addEventHandler('onClientRender', root, function ()
drawRectangle(500, 100, 200, 60, {
fill = {color = {51, 161, 224, 255}, radius = 6},
border = {color = {21, 77, 113, 255}, size = 2},
gradient = {direction = 'left', alpha_start = 100, alpha_end = 0},
})
drawRectangle(500, 200, 200, 60, {
fill = {color = {51, 161, 224, 255}, radius = 6},
border = {color = {21, 77, 113, 255}, size = 2, progress = 75, progress_color = {0, 255, 0, 255}},
})
drawRectangle(500, 300, 200, 60, {
fill = {color = {51, 161, 224, 255}, radius = 6},
border = {color = {21, 77, 113, 255}, size = 2, progress = 50, progress_color = {0, 255, 0, 255}},
gradient = {direction = 'top', alpha_start = 100, alpha_end = 0},
})
end)