def _determine_focus(self):
        # enforce int-only positioning of focus
        fx = int(self.fx)
        fy = int(self.fy)

        if self.allow_oob: return (fx, fy)

        # check that any layer has bounds
        bounded = []
        for layer in self.layers:
            # XXX isinstance Map instead?
            if hasattr(layer, 'pixel_width'):
                bounded.append(layer)
        if not bounded:
            return (fx, fy)

        # figure the bounds min/max
        m = bounded[0]
        b_min_x = m.x
        b_min_y = m.y
        b_max_x = m.x + m.pixel_width
        b_max_y = m.y + m.pixel_height
        for m in bounded[1:]:
            b_min_x = min(b_min_x, m.x)
            b_min_y = min(b_min_y, m.y)
            b_max_x = min(b_max_x, m.x + m.pixel_width)
            b_max_y = min(b_max_y, m.y + m.pixel_height)

        # figure the view min/max based on focus
        w2 = self.width/2
        h2 = self.height/2

        v_min_x = fx - w2
        v_min_y = fy - h2
        x_moved = y_moved = False
        if v_min_x < b_min_x:
            fx += b_min_x - v_min_x
            x_moved = True
        if v_min_y < b_min_y:
            fy += b_min_y - v_min_y
            y_moved = True

        v_max_x = fx + w2
        v_max_y = fy + h2
        if not x_moved and v_max_x > b_max_x:
            fx -= v_max_x - b_max_x
        if not y_moved and v_max_y > b_max_y:
            fy -= v_max_y - b_max_y

        return map(int, (fx, fy))
Determine the focal point of the view based on foxus (fx, fy),
dataset/ETHPy150Open ardekantur/pyglet/contrib/spryte/view.py/View._determine_focus