Snow-Man Posted January 10, 2017 Share Posted January 10, 2017 i have made login with dx and when i use normal screen positions for dx function works good after that i have added function guiGetScreenSize() to dx got wrong positions and wrong hover colors for dx Text here's my code help local msX, msY = 1280,1024 local sX, sY = guiGetScreenSize() function isMouseWithinRangeOf(x1,y1,x2,y2,type) if not isCursorShowing() then return false end local cx,cy = getCursorPosition() cx,cy = cx*sX,cy*sY if cx >= x1 and cx <= (type == true and x2 + x1 or x2) and cy >= y1 and cy <= (type == true and y2 + y1 or y2) then return true,cx,cy else return false end end function renderDxLogin() if isTransferBoxActive() then return end if isPlayerLoggedin() then hideLoginDX() return end if isPanelVisible then if not isCursorShowing() then showCursor(true) end if isChatVisible() then showChat(false) end end if isMouseWithinRangeOf(324, 485, 182, 57, true)then r, g, b = 255, 100, 100 elseif isMouseWithinRangeOf(sX-713, sY-539, 748, 541, true) then r1, g1, b1 = 255, 100, 100 elseif isMouseWithinRangeOf(sX-489, sY-539, 972, 541) then r2, g2, b2 = 255, 100, 100 else r, g, b = 255, 255, 255 end dxDrawRectangle(sX-956, sY-773, 658, 220, tocolor(0, 0, 0, 150), false) dxDrawBorderedText(welcomemsg, sX-958, sY-828, 982, 247, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "center", "center", false, false, false, false, false) dxDrawText("Username : ", sX-951, sY-730, 500, 325, tocolor(255, 255, 255, 255), 0.90, "bankgothic", "left", "top", false, false, false, false, false) dxDrawText("Password :", sX-951, sY-682, 500, 373, tocolor(255, 255, 255, 255), 0.90, "bankgothic", "left", "top", false, false, false, false, false) DxDrawBorderedRectangle(sX-956, sY-539, 181, 56, tocolor(0, 0, 0, 150), false) DxDrawBorderedRectangle(sX-713, sY-539, 181, 56, tocolor(0, 0, 0, 150), false) DxDrawBorderedRectangle(sX-489, sY-539, 181, 56, tocolor(0, 0, 0, 150), false) --dxDrawBorderedText("Login", sX-956, sY-539, 505, 541, tocolor(r,g, b, 255), 1.00, "bankgothic", "center", "center", false, false, false, false, false) dxDrawBorderedText("Login", (323 / msX) * sX, (539 / msY) * sY, 505, 541, tocolor(r,g, b, 255), 1.00, "bankgothic", "center", "center", false, false, false, false, false) dxDrawBorderedText("Register", sX-713, sY-539, 748, 541, tocolor(r1,g1, b1, 255), 1.00, "bankgothic", "center", "center", false, false, false, false, false) dxDrawBorderedText("Updates", sX-489, sY-539, 972, 541, tocolor(r2,g2, b2, 255), 1.00, "bankgothic", "center", "center", false, false, false, false, false) --(567 / nX) * sX, (433 / nY) * sY 323, 485 end addEventHandler("onClientClick", root, function(button, state, absoluteX, absoluteY) if not isPanelVisible then return end if button ~= "left" then return end if state ~= "down" then return end if isMouseWithinRangeOf((323 / msX) * sX, (539 / msY) * sY, 505, 541, true) then triggerServerEvent("onPlayerLoginSuccess", localPlayer , guiGetText(edit[1]),guiGetText(edit[2])) elseif isMouseWithinRangeOf(sX-713, sY-539, 748, 541, true) then triggerServerEvent("onPlayerRegisterSuccess", localPlayer, guiGetText(edit[1]),guiGetText(edit[2])) end end) i know i didn't put all variables of my script almost of them are true Link to comment
Best-Killer Posted January 10, 2017 Share Posted January 10, 2017 use this better function cursorPosition(x, y, w, h) if (not isCursorShowing()) then return false end local mx, my = getCursorPosition() local fullx, fully = guiGetScreenSize() cursorx, cursory = mx*fullx, my*fully if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then return true else return false end end Link to comment
</Mr.Tn6eL> Posted January 10, 2017 Share Posted January 10, 2017 (edited) 13 minutes ago, Best-Killer said: use this better What about this? function isMouseInPosition(x, y, w, h) if isCursorShowing( ) then local cx, cy = getCursorPosition( ) local sx, sy = guiGetScreenSize( ) cx, cy = cx*sx, cy*sy return cx >= x and cx <= x+w and cy >= y and cy <= y+h end return false end Edited January 10, 2017 by </Mr.Tn6eL> Link to comment
myonlake Posted January 10, 2017 Share Posted January 10, 2017 (edited) 4 hours ago, said: What about this? function isMouseInPosition(x, y, w, h) if isCursorShowing( ) then local cx, cy = getCursorPosition( ) local sx, sy = guiGetScreenSize( ) cx, cy = cx*sx, cy*sy return cx >= x and cx <= x+w and cy >= y and cy <= y+h end return false end Even shorter. -- bool Vector2:within ( Vector2 position, Vector2 size ) function Vector2:within( position, size ) local diff = ( self - position ) / size return diff.x >= 0 and diff.x <= 1 and diff.y >= 0 and diff.y <= 1 end local cursor = Vector2( getCursorPosition( ) ) * Vector2( guiGetScreenSize( ) ) local position, size = Vector2( 500, 500 ), Vector2( 50, 50 ) if ( isCursorShowing( ) ) and ( cursor:within( position, size ) ) then -- cursor (enabled with showCursor) is inside area end if ( getCursorPosition( ) ) and ( cursor:within( position, size ) ) then -- cursor is inside area end Edited January 10, 2017 by myonlake Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now