Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions arcade/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,31 +915,29 @@ def on_mouse_leave(self, x: int, y: int):
"""
pass

def absolute(self, normalized_pos: tuple[float, float]) -> tuple[float, float]:
"""Convert a position in normalized form to pixel-based, absolute form.
def absolute(self, fractional_pos: tuple[float, float]) -> tuple[float, float]:
"""Convert a relative fractional pair to absolute screen pixels.

:param normalized_pos: a tuple of two floats, representing a position,
where 0.0 -> 1.0 in the x represents the far left and right of the window,
and 0.0 -> 1.0 in the y represents the very bottom and the very top.
As in the rest of arcade and OpenGL, the default coordinate system
places the origin at the bottom left.

Returns a tuple of floats in pixels.
:param fractional_pos: A position where the x and y are fractional
values of the window size.
:returns: A tuple of absolute pixel X and Y relative to bottom left.
"""

w, h = self.size
return (normalized_pos[0] * w, normalized_pos[1] * h)

def relative(self, pos: tuple[float, float]) -> tuple[float, float]:
"""Convert a absolute position to coordinates in screenspace.
frac_x, frac_y = fractional_pos
return frac_x * w, frac_y * h

:param pos: a tuple of two floats, representing a position in pixels.
def relative(self, pixel_pos: tuple[float, float]) -> tuple[float, float]:
"""Convert absolute screen pixels to a relative fractional pair.

Returns a tuple of floats where 0.0 -> 1.0 in the x represents the
far left and right of the window, and 0.0 -> 1.0 in the y represents
the very bottom and the very top.
:param pixel_pos: a tuple of X and Y pixel positions within the window.
:returns: A tuple of fractional X and Y relative to the bottom left.
"""

w, h = self.size
return (pos[0] / w, pos[1] / h)
pixel_x, pixel_y = pixel_pos
return pixel_x / w, pixel_y / pixel_y


def open_window(
Expand Down