function UiTranslateToScreenCenter(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local sx = UiGetScale() if sx == 0 then return end local cx = UiGetCursorPos() local cW = UiCanvasSize().w local tc = cW / 2 UiTranslate((tc - cx) / sx + offsetX, offsetY) end function UiTranslateToScreenMiddle(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local _, sy = UiGetScale() if sy == 0 then return end local _, cy = UiGetCursorPos() local cH = UiCanvasSize().h local tm = cH / 2 UiTranslate(offsetX, (tm - cy) / sy + offsetY) end function UiTranslateToScreenRightEdge(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local sx = UiGetScale() if sx == 0 then return end local cx = UiGetCursorPos() local tc = UiCanvasSize().w UiTranslate((tc - cx) / sx + offsetX, offsetY) end function UiTranslateToScreenLeftEdge(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local sx = UiGetScale() if sx == 0 then return end local cx = UiGetCursorPos() UiTranslate(-cx / sx + offsetX, offsetY) end function UiTranslateToScreenTopEdge(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local _, sy = UiGetScale() if sy == 0 then return end local _, cy = UiGetCursorPos() UiTranslate(offsetX, -cy / sy + offsetY) end function UiTranslateToScreenBottomEdge(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local _, sy = UiGetScale() if sy == 0 then return end local cH = UiCanvasSize().h local _, cy = UiGetCursorPos() UiTranslate(offsetX, (cH - cy) / sy + offsetY) end function UiTranslateToWindowCenter(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local sx = UiGetScale() if sx == 0 then return end local cx = UiGetCursorPos() local x1, _, x2, _ = UiGetCurrentWindow() local wc = x1 + (x2 - x1) / 2 UiTranslate((wc - cx) / sx + offsetX, offsetY) end function UiTranslateToWindowMiddle(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local _, sy = UiGetScale() if sy == 0 then return end local _, cy = UiGetCursorPos() local _, y1, _, y2 = UiGetCurrentWindow() local wc = y1 + (y2 - y1) / 2 UiTranslate(offsetX, (wc - cy) / sy + offsetY) end function UiTranslateToWindowRightEdge(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local sx = UiGetScale() if sx == 0 then return end local cx = UiGetCursorPos() local _, _, wx, _ = UiGetCurrentWindow() UiTranslate((wx - cx) / sx + offsetX, offsetY) end function UiTranslateToWindowLeftEdge(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local sx = UiGetScale() if sx == 0 then return end local cx = UiGetCursorPos() local wx, _, _, _ = UiGetCurrentWindow() UiTranslate((wx - cx) / sx + offsetX, offsetY) end function UiTranslateToWindowTopEdge(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local _, sy = UiGetScale() if sy == 0 then return end local _, cy = UiGetCursorPos() local _, wy, _, _ = UiGetCurrentWindow() UiTranslate(offsetX, (wy - cy) / sy + offsetY) end function UiTranslateToWindowBottomEdge(offsetX, offsetY) offsetX = offsetX or 0 offsetY = offsetY or 0 local _, sy = UiGetScale() if sy == 0 then return end local _, _, _, wy = UiGetCurrentWindow() local _, cy = UiGetCursorPos() UiTranslate(offsetX, (wy - cy) / sy + offsetY) end function UiTranslateToWindowTopLeft(offsetX, offsetY) UiTranslateToWindowTopEdge() UiTranslateToWindowLeftEdge(offsetX, offsetY) end function UiTranslateToPositionOnScreen(x, y) local cx, cy = UiGetCursorPos() local sx, sy = UiGetScale() if sx == 0 or sy == 0 then return end UiTranslate((x - cx) / sx, (y - cy) / sy) end