functional

This commit is contained in:
2021-06-21 22:33:08 -05:00
parent 7c0d74f450
commit 1cc0b6efc3
2 changed files with 75 additions and 22 deletions

View File

@@ -2,35 +2,62 @@ simulated_resolution = v2(1920, 1080)
function coords_to_screenwriter(coord1, coord2) function coords_to_screenwriter(coord1, coord2)
local x_left, x_right, y_top, y_bottom, width, height
x_left = math.min(coord1.x, coord2.x) x_left = math.min(coord1.x, coord2.x)
x_right = math.max(coord1.x, coord2.x) x_right = math.max(coord1.x, coord2.x)
y_top = math.min(coord1.y, coord2.y) y_top = math.min(coord1.y, coord2.y)
y_bottom = math.max(coord1.y, coord2.y) y_bottom = math.max(coord1.y, coord2.y)
width_px = x_right - x_left width = x_right - x_left
height_px = y_bottom - y_top height = y_bottom - y_top
x_px = x_left + width_px / 2 return coords_partial_to_screenwriter(v2(x_left, x_top), v2(width, height), 1)
y_px = y_top + height_px / 2
x = (x_px - simulated_resolution.x / 2) / simulated_resolution.x * 2 end
y = (y_px - simulated_resolution.y / 2) / simulated_resolution.y * 2
width = (width_px - simulated_resolution.x / 2) / simulated_resolution.x * 2 function coords_partial_to_screenwriter(pos_px, scale_px, anchor)
height = (height_px - simulated_resolution.y / 2) / simulated_resolution.y * 2
local x_px, y_px, x, y, width, height
if anchor == 1 then --top left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 2 then --top right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 3 then --bottom right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
elseif anchor == 4 then --bottom left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
else --center
x_px = pos_px.x
y_px = pos_px.y
end
x = x_px / simulated_resolution.x * 2 - 1
y = y_px / simulated_resolution.y * 2 - 1
width = scale_px.x / simulated_resolution.x * 2
height = scale_px.y / simulated_resolution.y * 2
return v2(x, y), v2(width, height) return v2(x, y), v2(width, height)
end end
--menu.add_feature("player coords", "toggle", 0, function(f) local disable_bg = menu.add_feature("disable background", "toggle")
menu.create_thread(function() menu.create_thread(function()
local scale = -2
--while f.on do
while true do while true do
local pos, scale = coords_to_screenwriter(v2(1920, 0), v2(1728, 108))
scriptdraw.draw_rect(pos, scale, 0xFF000000) local base = v2(320, 20)
if (not(disable_bg.on)) then
local pos, scale = coords_partial_to_screenwriter(base, v2(200, 200), 4)
scriptdraw.draw_rect(pos, scale, 0xFF000000)
end
--scriptdraw.draw_text(scale, v2(0, 0), v2(1, 1), 1, 0XFFFFFFFF, 0) --scriptdraw.draw_text(scale, v2(0, 0), v2(1, 1), 1, 0XFFFFFFFF, 0)
system.wait(0) system.wait(0)
end end
--end)
end, nil) end, nil)

View File

@@ -2,6 +2,8 @@ simulated_resolution = v2(1920, 1080)
function screenwriter_to_coords(pos, scale) function screenwriter_to_coords(pos, scale)
local x, y, width, height, x_px, y_px, width_px, height_px, x_left, x_right, y_top, y_bottom
x = pos.x x = pos.x
y = pos.y y = pos.y
width = scale.x width = scale.x
@@ -23,21 +25,45 @@ end
function coords_to_screenwriter(coord1, coord2) function coords_to_screenwriter(coord1, coord2)
local x_left, x_right, y_top, y_bottom, width, height
x_left = math.min(coord1.x, coord2.x) x_left = math.min(coord1.x, coord2.x)
x_right = math.max(coord1.x, coord2.x) x_right = math.max(coord1.x, coord2.x)
y_top = math.min(coord1.y, coord2.y) y_top = math.min(coord1.y, coord2.y)
y_bottom = math.max(coord1.y, coord2.y) y_bottom = math.max(coord1.y, coord2.y)
width_px = x_right - x_left width = x_right - x_left
height_px = y_bottom - y_top height = y_bottom - y_top
x_px = x_left + width_px / 2 return coords_partial_to_screenwriter(v2(x_left, x_top), v2(width, height), 1)
y_px = y_top + height_px / 2
x = (x_px - simulated_resolution.x / 2) / simulated_resolution.x * 2 end
y = (y_px - simulated_resolution.y / 2) / simulated_resolution.y * 2
width = (width_px - simulated_resolution.x / 2) / simulated_resolution.x * 2 function coords_partial_to_screenwriter(pos_px, scale_px, anchor)
height = (height_px - simulated_resolution.y / 2) / simulated_resolution.y * 2
local x_px, y_px, x, y, width, height
if anchor == 1 then --top left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
elseif anchor == 2 then --top right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
elseif anchor == 3 then --bottom right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 4 then --bottom left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
else --center
x_px = pos_px.x
y_px = pos_px.y
end
x = x_px / simulated_resolution.x * 2 - 1
y = y_px / simulated_resolution.y * 2 - 1
width = scale_px.x / simulated_resolution.x * 2
height = scale_px.y / simulated_resolution.y * 2
return v2(x, y), v2(width, height) return v2(x, y), v2(width, height)