local resize = 1
local reiszes = {
["2560x1440"] = 1.4,
["1920x1200"] = 1.14,
["1920x1080"] = 1.14,
["1760x990"] = 1.1,
["1680x1050"] = 1.1,
["1600x1200"] = 1.1,
["1600x900"] = 1.1,
["1440x900"] = 1.1,
["1366x768"] = 0.9,
["1360x768"] = 0.9,
["1280x1024"] = 0.8,
["1280x800"] = 0.8,
["1280x720"] = 0.8,
["1128x634"] = 0.76,
["1024x768"] = 0.7,
["800x600"] = 0.7,
["720x480"] = 0.46,
["640x480"] = 0.4,
}

function isButtonKey ( s )
local keyTable = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse_wheel_up", "mouse_wheel_down", "arrow_l", "arrow_u",
"arrow_r", "arrow_d", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "num_0", "num_1", "num_2", "num_3", "num_4", "num_5",
"num_6", "num_7", "num_8", "num_9", "num_mul", "num_add", "num_sep", "num_sub", "num_div", "num_dec", "num_enter", "F1", "F2", "F3", "F4", "F5",
"F6", "F7", "F8", "F9", "F10", "F11", "F12", "escape", "backspace", "tab", "lalt", "ralt", "enter", "space", "pgup", "pgdn", "end", "home",
"insert", "delete", "lshift", "rshift", "lctrl", "rctrl", "[", "]", "pause", "capslock", "scroll", ";", ",", "-", ".", "/", "#", "\\", "=" }
for i=1, #keyTable do
if keyTable[ i ] == s then
return true
end
end
return false
end

function getResize ( )
local sw, sh = guiGetScreenSize( )
local t = sw .. "x" .. sh
if reiszes[ t ] then
resize = reiszes[ t ]
return true
end
resize = 1
return false
end

function setResize( n, max )
if max and n * resize >= max then
return max
end
return n * resize
end

function getSizeImage ( image )
local myTexture = dxCreateTexture( image )
return dxGetMaterialSize( myTexture )
end


function getElementDistance ( element1, element2, radius )
    if getElementType( element1 ) and getElementType( element2 ) and type( radius ) == "number" then
        local x1, y1, z1 = getElementPosition( element1 )
        local x2, y2, z2 = getElementPosition( element2 )
        if x1 and x2 then
            if getDistanceBetweenPoints3D( x1, y1, z1, x2, y2, z2 ) <= radius then
                return true
            end
        end
    end
    return false
end

function isTimerTick ( timer, count )
return ( getTickCount( ) - count ) / ( 1000 * timer )
end

function interpolatePositionWithEasing ( timer, count, x1, x2, strEasingType )
strEasingType = strEasingType or "Linear"
local x1, y1, z1, x2, y2, z2 = x1, 0, 0, x2, 0, 0
-- https://wiki.multitheftauto.com/wiki/Easing
return interpolateBetween( x1, y1, z1, x2, y2, z2, ( getTickCount( ) - count ) / ( 1000 * timer ), strEasingType )
end

function cursorPosition ( )
    if isCursorShowing( ) then
local screenx, screeny, worldx, worldy, worldz = getCursorPosition( )
        local sw, sh = guiGetScreenSize( )
        return { x = screenx * sw, y = screeny * sh}
    end
    return { x = 0, y = 0 }
end


function dxDrawRoundedRectangleTop ( x, y, rx, ry, color, r, postGUI )
local rn = ry
if ry > rx then
rn = rx
end
local radius = rn * 0.5 * r
rx = rx - radius * 2
ry = ry - radius * 2
x = x + radius
y = y + radius

if (rx >= 0) and (ry >= 0) then
dxDrawRectangle(x, y, rx, ry, color, postGUI)
dxDrawRectangle(x, y - radius, rx, radius, color, postGUI)
dxDrawRectangle(x, y + ry, rx, radius, color, postGUI)

dxDrawCircle(x, y, radius, 180, 270, color, color, 7, 1, postGUI)
dxDrawRectangle(x - radius, y, radius, ry + radius, color, postGUI)

dxDrawCircle(x + rx, y, radius, 270, 360, color, color, 7, 1, postGUI)
dxDrawRectangle(x + rx, y, radius, ry + radius, color, postGUI)
end
end

function dxDrawRoundedRectangleBottom ( x, y, rx, ry, color, r, postGUI )
local rn = ry
if ry > rx then
rn = rx
end
local radius = rn * 0.5 * r
rx = rx - radius * 2
ry = ry - radius * 2
x = x + radius
y = y + radius

if (rx >= 0) and (ry >= 0) then
dxDrawRectangle(x, y, rx, ry, color, postGUI)
dxDrawRectangle(x, y - radius, rx, radius, color, postGUI)
dxDrawRectangle(x, y + ry, rx, radius, color, postGUI)

dxDrawCircle(x + rx, y + ry, radius, 0, 90, color, color, 7, 1, postGUI )
dxDrawRectangle(x - radius, y - radius, radius, ry + radius, color, postGUI)

dxDrawCircle(x, y + ry, radius, 90, 180, color, color, 7, 1, postGUI )
dxDrawRectangle(x + rx, y - radius, radius, ry + radius, color, postGUI)

end
end


function dxDrawRoundedRectangleRight ( x, y, rx, ry, color, r, postGUI )
local rn = ry
if ry > rx then
rn = rx
end
local radius = rn * 0.5 * r

rx = rx - radius * 2
ry = ry - radius * 2
x = x + radius
y = y + radius

if (rx >= 0) and (ry >= 0) then
dxDrawRectangle(x, y, rx, ry, color, postGUI)
dxDrawRectangle(x - radius, y - radius, rx + radius, radius, color, postGUI)
dxDrawRectangle(x - radius, y + ry, rx + radius, radius, color, postGUI)
dxDrawRectangle(x - radius, y, radius, ry, color, postGUI)
dxDrawRectangle(x + rx, y, radius, ry, color, postGUI)

--dxDrawCircle(x, y, radius, 180, 270, color, color, 7, 1, postGUI)
dxDrawCircle(x + rx, y, radius, 270, 360, color, color, 7, 1, postGUI)
dxDrawCircle(x + rx, y + ry, radius, 0, 90, color, color, 7, 1, postGUI )
--dxDrawCircle(x, y + ry, radius, 90, 180, color, color, 7, 1, postGUI )

end
end

function dxDrawRoundedRectangleLeft ( x, y, rx, ry, color, r, postGUI )
local rn = ry
if ry > rx then
rn = rx
end
local radius = rn * 0.5 * r

rx = rx - radius * 2
ry = ry - radius * 2
x = x + radius
y = y + radius

if (rx >= 0) and (ry >= 0) then
dxDrawRectangle(x, y, rx, ry, color, postGUI)
dxDrawRectangle(x, y - radius, rx + radius, radius, color, postGUI)
dxDrawRectangle(x, y + ry, rx + radius, radius, color, postGUI)
dxDrawRectangle(x - radius, y, radius, ry, color, postGUI)
dxDrawRectangle(x + rx, y, radius, ry, color, postGUI)

dxDrawCircle(x, y, radius, 180, 270, color, color, 7, 1, postGUI)
--dxDrawCircle(x + rx, y, radius, 270, 360, color, color, 7, 1, postGUI)
--dxDrawCircle(x + rx, y + ry, radius, 0, 90, color, color, 7, 1, postGUI )
dxDrawCircle(x, y + ry, radius, 90, 180, color, color, 7, 1, postGUI )

end
end

function dxDrawRoundedRectangle ( x, y, rx, ry, color, r, postGUI )
local rn = ry
if ry > rx then
rn = rx
end
local radius = rn * 0.5 * r

rx = rx - radius * 2
ry = ry - radius * 2
x = x + radius
y = y + radius

if (rx >= 0) and (ry >= 0) then
dxDrawRectangle(x, y, rx, ry, color, postGUI)
dxDrawRectangle(x, y - radius, rx, radius, color, postGUI)
dxDrawRectangle(x, y + ry, rx, radius, color, postGUI)
dxDrawRectangle(x - radius, y, radius, ry, color, postGUI)
dxDrawRectangle(x + rx, y, radius, ry, color, postGUI)

dxDrawCircle(x, y, radius, 180, 270, color, color, 7, 1, postGUI)
dxDrawCircle(x + rx, y, radius, 270, 360, color, color, 7, 1, postGUI)
dxDrawCircle(x + rx, y + ry, radius, 0, 90, color, color, 7, 1, postGUI )
dxDrawCircle(x, y + ry, radius, 90, 180, color, color, 7, 1, postGUI )

end
end

function dxDrawButtonRounded ( text, x, y, w, h, color, hitColor, clickColor, textColor, hitTextColor, textClickColor, textShadowColor, font, scale, textShadowSize, hitState, clickState, radius, postGUI )
local theColor = color
local theTextColor = textColor

if isMouseWithinRangeOf( x, y, w, h ) and hitState == true then
theColor = hitColor
theTextColor = hitTextColor
end

if clickState and type( clickState ) == "string" then
if clickState == "mouse1" or clickState == "mouse2" or clickState == "mouse3" then
if isMouseWithinRangeOf( x, y, w, h ) then
if getKeyState( clickState ) then
theColor = clickColor
theTextColor = textClickColor
end
end
end
elseif clickState and type( clickState ) == "table" then
for i,v in ipairs( clickState ) do
if isButtonKey ( v ) then
if isMouseWithinRangeOf( x, y, w, h ) then
theColor = clickColor
theTextColor = textClickColor
end
end
end
end

dxDrawRoundedRectangle ( x, y, w, h, theColor, radius, postGUI )

text = text or ""
font = font or "default-bold"
scale = scale or 1
local textWidth = dxGetTextWidth( string.gsub( text, "#%x%x%x%x%x%x", "" ), scale, font )
local textHeight = dxGetFontHeight( scale, font )

dxDrawText( string.gsub( text, "#%x%x%x%x%x%x", "" ), x + ( w/2 - textWidth/2 ) + textShadowSize, y + ( h/2 - textHeight/2 ) + textShadowSize, textWidth, textHeight, textShadowColor, scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )

dxDrawText( text, x + ( w/2 - textWidth/2 ), y + ( h/2 - textHeight/2 ), textWidth, textHeight, theTextColor, scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
end

function roundedRectangle( x, y, w, h, borderColor, bgColor, postGUI )
if not ( postGUI == true or postGUI == false ) then postGUI = false end
    if (x and y and w and h) then
        if (not borderColor) then
            borderColor = tocolor(0, 0, 0, 200);
        end
if not ( bgColor ) then
bgColor = borderColor;
end

if ( type(bgColor) == "string") then
dxDrawImage( x, y, w, h, bgColor, 0, 0, 0, tocolor( 255, 255, 255, 255 ), postGUI )
end
dxDrawRectangle(x, y, w, h, bgColor, postGUI);

dxDrawRectangle(x - 1, y - 1, w + 2, 1, borderColor, postGUI);
dxDrawRectangle(x - 1, y + h, w + 2, 1, borderColor, postGUI);
        dxDrawRectangle(x - 1, y + 0, 1, h - 0, borderColor, postGUI);
        dxDrawRectangle(x + w, y + 0, 1, h - 0, borderColor, postGUI);
    end
end

function roundedRectangleGlow ( x, y, w, h, borderColor, bgColor, glow, thickness, postGUI )
local r, g, b, a = tocolorToRGBA ( borderColor )
local plus = 0
for i=1, glow do
plus = plus + thickness
local alpha = a/glow*( glow-i )
if alpha >= 1 then
roundedRectangle( x - plus, y - plus, w + plus * 2, h + plus * 2, tocolor( r, g, b, alpha ), bgColor, postGUI )
end
end
end

function tocolorToRGBA ( color )
local alpha = bitExtract( color, 24, 8)
local red = bitExtract( color, 16, 8)
local green = bitExtract( color, 8, 8)
local blue = bitExtract( color, 0, 8)
return red, green, blue, alpha
end

function isMouseWithinRangeOf ( psx, psy, pssx, pssy )
if not isCursorShowing ( ) then
return false
end
    local cx, cy = getCursorPosition( )
    local sw, sh = guiGetScreenSize( )
cx, cy = cx * sw, cy * sh
if cx >= psx and cx <= psx + pssx and cy >= psy and cy <= psy + pssy then
return true,cx,cy
else
return false
end
end

function dxDrawTextShadow ( text, x, y, w, h, color, colorHit, shadowColor, shadowColorHit, sizeShadow, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY )

local text = tostring( text )
local scale = scale or 1
local font = font or "default-bold"
local textWidth = dxGetTextWidth( string.gsub( text, "#%x%x%x%x%x%x", "" ), scale, font )
local textHeight = dxGetFontHeight( scale, font )

local posX = 0
local posY = 0

if alignX == "center" then
posX = w/2 - textWidth/2
elseif alignX == "right" then
posX = w - textWidth
end

if alignY == "center" then
posY = h/2 - textHeight/2
elseif alignY == "right" then
posY = h - textHeight
end

clip = clip or false
wordBreak = wordBreak or false
postGUI = postGUI or false
colorCoded = colorCoded or false
subPixelPositioning = subPixelPositioning or false
fRotation = fRotation or 0
fRotationCenterX = fRotationCenterX or 0
fRotationCenterY = fRotationCenterY or 0

if isMouseWithinRangeOf( x, y, w, h ) then
color = colorHit
shadowColor = shadowColorHit
end


dxDrawText( string.gsub( text, "#%x%x%x%x%x%x", "" ), x + posX + sizeShadow, y + posY + sizeShadow, textWidth, textHeight, shadowColor, scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
dxDrawText( string.gsub( text, "#%x%x%x%x%x%x", "" ), x + posX - sizeShadow, y + posY - sizeShadow, textWidth, textHeight, shadowColor, scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
dxDrawText( string.gsub( text, "#%x%x%x%x%x%x", "" ), x + posX + sizeShadow, y + posY - sizeShadow, textWidth, textHeight, shadowColor, scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
dxDrawText( string.gsub( text, "#%x%x%x%x%x%x", "" ), x + posX - sizeShadow, y + posY + sizeShadow, textWidth, textHeight, shadowColor, scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
dxDrawText( text, x + posX, y + posY, textWidth, textHeight, color, scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
return textWidth, textHeight
end

function dxDrawShadedText(text, leftX, topY, rightX, bottomY, color, shadowColor, offsetX, offsetY, ...)
rightX = rightX or 0
bottomY = bottomY or 0
shadowColor = shadowColor or -16777216
dxDrawText(text, leftX + offsetX, topY + offsetY, rightX + offsetX, rightX + offsetY, shadowColor, ...)
dxDrawText(text, leftX, topY, rightX, rightX, color, ...)
end

function removeColorCoding ( text )
    return type( text )=='string' and string.gsub ( text, "#%x%x%x%x%x%x", "" ) or text
end

function dxDrawbutton ( text, posx, posy, width, height, borderColor, bgColor, colorText, colorClick, colorHit, font, scale, enabled, postGUI )

if not enabled then
bgColor = tocolor( 0, 0, 0, 0 )
colorHit = tocolor( 0, 0, 0, 0 )
end
if isMouseWithinRangeOf ( posx, posy, width, height ) then
bgColor = colorHit
if getKeyState( "mouse1" ) and enabled then
bgColor = colorClick
end
end

roundedRectangle( posx, posy, width, height, borderColor, bgColor, postGUI )

colorText = colorText or tocolor ( 255, 255, 255, 255 )
font = font or "default-bold"
scale = scale or 1.12
local textWidth = dxGetTextWidth( string.gsub( text, "#%x%x%x%x%x%x", "" ), scale, font )
local textHeight = dxGetFontHeight( scale, font )

local outline = (scale or 1) * (1.333333333333334 * ( 1 ))
dxDrawText( removeColorCoding ( text ), posx + ( width/2 - textWidth/2 ) - outline, posy + ( height/2 - textHeight/2 ) - outline, textWidth - outline, textHeight - outline, tocolor( 26, 26, 26, 255 ), scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
dxDrawText( removeColorCoding ( text ), posx + ( width/2 - textWidth/2 ) + outline, posy + ( height/2 - textHeight/2 ) - outline, textWidth + outline, textHeight - outline, tocolor( 26, 26, 26, 255 ), scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
dxDrawText( removeColorCoding ( text ), posx + ( width/2 - textWidth/2 ) - outline, posy + ( height/2 - textHeight/2 ) + outline, textWidth - outline, textHeight + outline, tocolor( 26, 26, 26, 255 ), scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )
dxDrawText( removeColorCoding ( text ), posx + ( width/2 - textWidth/2 ) + outline, posy + ( height/2 - textHeight/2 ) + outline, textWidth + outline, textHeight + outline, tocolor( 26, 26, 26, 255 ), scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )

dxDrawText( text, posx + ( width/2 - textWidth/2 ), posy + ( height/2 - textHeight/2 ), textWidth, textHeight, colorText, scale, font, "left", "top", false, false, postGUI, true, false, 0, 0, 0 )

end

-- drawWavingRectangle ( 500, 500, 50, 50, tocolor(26, 255, 26, 255), 2, 4, 1, true )
function drawWavingRectangle ( x, y, w, h, color, width, frequency, amplitude, _postGUI )
local currentTime = getTickCount()
local speed = 0.005 -- ปรับความเร็วในการเคลื่อนไหว
local Offset = width * amplitude * math.sin(currentTime * speed * frequency)
x, y, w, h = x - Offset, y - Offset, w + (Offset * 2), h + (Offset * 2)
dxDrawLine( x, y, x + w, y, color, width, _postGUI )
dxDrawLine( x, y, x, y + h, color, width, _postGUI )
dxDrawLine( x + w, y, x + w, y + h, color, width, _postGUI )
dxDrawLine( x, y + h, x + w, y + h, color, width, _postGUI )
end

function drawLineRectangle ( x, y, w, h, color, width, _postGUI )
dxDrawLine( x, y, x + w, y, color, width, _postGUI )
dxDrawLine( x, y, x, y + h, color, width, _postGUI )
dxDrawLine( x + w, y, x + w, y + h, color, width, _postGUI )
dxDrawLine( x, y + h, x + w, y + h, color, width, _postGUI )
end

-- x, y, w, h, color, gradientColor, length, width,_postGUI
-- x, y, w, h, tocolor( 255, 255, 255, 255 ), 1, 4, 2, false
function drawGradientRectangle ( x, y, w, h, color, gradientColor, length, width, _postGUI )
local r = bitExtract( color, 16, 8)
local g = bitExtract( color, 8, 8)
local b = bitExtract( color, 0, 8)
local a = bitExtract( color, 24, 8)
drawLineRectangle ( x, y, w, h, color, width, _postGUI )
for i=1,length do
local _p = width * i
local alpha = a/length*( length-i )
drawLineRectangle ( x - _p, y - _p, w + ( _p * 2 ), h + ( _p * 2 ), tocolor( r, g, b, alpha * gradientColor ), width, _postGUI )
end
end



ไม่มีความคิดเห็น:

แสดงความคิดเห็น