# Path: ui/stack/stack.py
# def stack(self, dimension, other, spacing = 0):
#   if self._backend.stacks():
#     offset = [0 for i in range(self.dimension())]
#     offset[dimension] = spacing
#     coords = list(self._coords)
#     for i in range(len(coords)):
#       if i == dimension:
#         coords[i] += spacing + other._coords[i]
#       else:
#         coords[i] = max(coords[i], other._coords[i])
#     return Stack(coords, self._backend.stack(dimension, other._backend.shift(offset)))
#   else:
#     offset = [0 for i in range(self.dimension())]
#     offset[dimension] = self.widths()[dimension] + spacing
#     return self.below(other.shift(offset))


from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from ui.stack import stack
    def f():
      glScale(-1.0, -1.0, 1.0)
      self.render()
      glScale(-1.0, -1.0, 1.0)
    return GLBackend(f)

  def below(self, other):
    assert(other.__class__ == GLBackend)
    def render():
      self.render()
      other.render()
    return GLBackend(render)

  def shift(self, offset):
    # No 4-Dimensional GLBackends allowed.
    assert(len(offset) <= 3)
    t = [0 for i in range(3)]
    for i in range(len(offset)):
      t[i] = offset[i]
    def render():
      glTranslate(t[0], t[1], t[2])
      self.render()
      glTranslate(-t[0], -t[1], -t[2])
    return GLBackend(render)

  @staticmethod
  def null():
    return GLBackend(lambda: None)

def newGLStack(widths, render):

# Path: ui/stack/stack.py
# def stack(self, dimension, other, spacing = 0):
#   if self._backend.stacks():
#     offset = [0 for i in range(self.dimension())]
#     offset[dimension] = spacing
#     coords = list(self._coords)
#     for i in range(len(coords)):
#       if i == dimension:
#         coords[i] += spacing + other._coords[i]
#       else:
#         coords[i] = max(coords[i], other._coords[i])
#     return Stack(coords, self._backend.stack(dimension, other._backend.shift(offset)))
#   else:
#     offset = [0 for i in range(self.dimension())]
#     offset[dimension] = self.widths()[dimension] + spacing
#     return self.below(other.shift(offset))


# Path: ui/stack/gl.py
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from ui.stack import stack

    def f():
      glScale(-1.0, -1.0, 1.0)
      self.render()
      glScale(-1.0, -1.0, 1.0)
    return GLBackend(f)

  def below(self, other):
    assert(other.__class__ == GLBackend)
    def render():
      self.render()
      other.render()
    return GLBackend(render)

  def shift(self, offset):
    # No 4-Dimensional GLBackends allowed.
    assert(len(offset) <= 3)
    t = [0 for i in range(3)]
    for i in range(len(offset)):
      t[i] = offset[i]
    def render():
      glTranslate(t[0], t[1], t[2])
      self.render()
      glTranslate(-t[0], -t[1], -t[2])
    return GLBackend(render)

  @staticmethod
  def null():
    return GLBackend(lambda: None)

def newGLStack(widths, render):

  return stack.Stack(widths, GLBackend(render))