def SpaceFromScreen(self, coords): screen_width = self.screen.get_width() screen_height = self.screen.get_height() x = coords[0] y = screen_height - coords[1] screen_rect = Rectangle(Vector(), Vector(screen_width, screen_height)) screen_rect.ShrinkToMatchAspectRatio(self.space_rect) space_pos = screen_rect.LinearMap(self.space_rect, Vector(x, y)) return space_pos
def SpaceToScreen(self, position): screen_width = self.screen.get_width() screen_height = self.screen.get_height() screen_rect = Rectangle(Vector(), Vector(screen_width, screen_height)) screen_rect.ShrinkToMatchAspectRatio(self.space_rect) screen_pos = self.space_rect.LinearMap(screen_rect, position) x = int(screen_pos.x) y = screen_height - int(screen_pos.y) #x = min(max(x, 0), screen_width - 1) #y = min(max(y, 0), screen_height - 1) return (x, y)