# Path: drawable.py
# class Drawable(object):
# 
#     def __init__(self):
#         super(Drawable, self).__init__()
#         self._displayList = None
#         self.invalidList = True
#         self.children = []
# 
#     def setUp(self):
#         """
#         Set up rendering settings and view matrices
#         :return:
#         :rtype:
#         """
# 
#     def tearDown(self):
#         """
#         Return any settings changed in setUp to their previous states
#         :return:
#         :rtype:
#         """
# 
#     def drawSelf(self):
#         """
#         Draw this drawable, if it has its own graphics.
#         :return:
#         :rtype:
#         """
# 
#     def _draw(self):
#         self.setUp()
#         self.drawSelf()
#         for child in self.children:
#             child.draw()
#         self.tearDown()
# 
#     def draw(self):
#         if self._displayList is None:
#            self._displayList = GL.glGenLists(1)
# 
#         if self.invalidList:
#             self.compileList()
# 
#         GL.glCallList(self._displayList)
# 
#     def compileList(self):
#         GL.glNewList(self._displayList, GL.GL_COMPILE)
#         self._draw()
#         GL.glEndList()
#         self.invalidList = False
# 
#     def invalidate(self):
#         self.invalidList = True
# 
# Path: glutils.py
# class gl(object):
#     @classmethod
#     def ResetGL(cls):
#         DisplayList.invalidateAllLists()
# 
#     @classmethod
#     @contextmanager
#     def glPushMatrix(cls, matrixmode):
#         try:
#             GL.glMatrixMode(matrixmode)
#             GL.glPushMatrix()
#             yield
#         finally:
#             GL.glMatrixMode(matrixmode)
#             GL.glPopMatrix()
# 
#     @classmethod
#     @contextmanager
#     def glPushAttrib(cls, attribs):
#         try:
#             GL.glPushAttrib(attribs)
#             yield
#         finally:
#             GL.glPopAttrib()
# 
#     @classmethod
#     @contextmanager
#     def glBegin(cls, type):
#         try:
#             GL.glBegin(type)
#             yield
#         finally:
#             GL.glEnd()
# 
#     @classmethod
#     @contextmanager
#     def glEnable(cls, *enables):
#         try:
#             GL.glPushAttrib(GL.GL_ENABLE_BIT)
#             for e in enables:
#                 GL.glEnable(e)
# 
#             yield
#         finally:
#             GL.glPopAttrib()
# 
#     @classmethod
#     @contextmanager
#     def glEnableClientState(cls, *enables):
#         try:
#             GL.glPushClientAttrib(GL.GL_CLIENT_ALL_ATTRIB_BITS)
#             for e in enables:
#                 GL.glEnableClientState(e)
# 
#             yield
#         finally:
#             GL.glPopClientAttrib()
# 
#     listCount = 0
# 
#     @classmethod
#     def glGenLists(cls, n):
#         cls.listCount += n
#         return GL.glGenLists(n)
# 
#     @classmethod
#     def glDeleteLists(cls, base, n):
#         cls.listCount -= n
#         return GL.glDeleteLists(base, n)
# 
# Path: mceutils.py
# def loadPNGTexture(filename, *a, **kw):
#     filename = os.path.join(directories.dataDir, filename)
#     try:
#         w, h, ndata = loadPNGFile(filename)
# 
#         tex = glutils.Texture(functools.partial(loadTextureFunc, w, h, ndata), *a, **kw)
#         tex.data = ndata
#         return tex
#     except Exception, e:
#         print "Exception loading ", filename, ": ", repr(e)
#         return glutils.Texture()


import logging
from OpenGL import GL
from drawable import Drawable
from glutils import gl
from mceutils import loadPNGTexture

    @yawPitch.setter
    def yawPitch(self, value):
        self._yawPitch = value
        self.invalidate()

    def drawSelf(self):
        if self._tex is None:
            if self.small:
                filename = "compass_small.png"
            else:
                filename = "compass.png"

            self._tex = loadPNGTexture("toolicons/" + filename)#, minFilter=GL.GL_LINEAR, magFilter=GL.GL_LINEAR)

        self._tex.bind()
        size = 0.075

        with gl.glPushMatrix(GL.GL_MODELVIEW):
            GL.glLoadIdentity()

            yaw, pitch = self.yawPitch
            GL.glTranslatef(1.-size, size, 0.0)  # position on upper right corner
            GL.glRotatef(180-yaw, 0., 0., 1.)  # adjust to north
            GL.glColor3f(1., 1., 1.)

            with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY):
                GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-size, -size, 2*size, 2*size))
                GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 256, 256))


# Path: drawable.py
# class Drawable(object):
# 
#     def __init__(self):
#         super(Drawable, self).__init__()
#         self._displayList = None
#         self.invalidList = True
#         self.children = []
# 
#     def setUp(self):
#         """
#         Set up rendering settings and view matrices
#         :return:
#         :rtype:
#         """
# 
#     def tearDown(self):
#         """
#         Return any settings changed in setUp to their previous states
#         :return:
#         :rtype:
#         """
# 
#     def drawSelf(self):
#         """
#         Draw this drawable, if it has its own graphics.
#         :return:
#         :rtype:
#         """
# 
#     def _draw(self):
#         self.setUp()
#         self.drawSelf()
#         for child in self.children:
#             child.draw()
#         self.tearDown()
# 
#     def draw(self):
#         if self._displayList is None:
#            self._displayList = GL.glGenLists(1)
# 
#         if self.invalidList:
#             self.compileList()
# 
#         GL.glCallList(self._displayList)
# 
#     def compileList(self):
#         GL.glNewList(self._displayList, GL.GL_COMPILE)
#         self._draw()
#         GL.glEndList()
#         self.invalidList = False
# 
#     def invalidate(self):
#         self.invalidList = True
# 
# Path: glutils.py
# class gl(object):
#     @classmethod
#     def ResetGL(cls):
#         DisplayList.invalidateAllLists()
# 
#     @classmethod
#     @contextmanager
#     def glPushMatrix(cls, matrixmode):
#         try:
#             GL.glMatrixMode(matrixmode)
#             GL.glPushMatrix()
#             yield
#         finally:
#             GL.glMatrixMode(matrixmode)
#             GL.glPopMatrix()
# 
#     @classmethod
#     @contextmanager
#     def glPushAttrib(cls, attribs):
#         try:
#             GL.glPushAttrib(attribs)
#             yield
#         finally:
#             GL.glPopAttrib()
# 
#     @classmethod
#     @contextmanager
#     def glBegin(cls, type):
#         try:
#             GL.glBegin(type)
#             yield
#         finally:
#             GL.glEnd()
# 
#     @classmethod
#     @contextmanager
#     def glEnable(cls, *enables):
#         try:
#             GL.glPushAttrib(GL.GL_ENABLE_BIT)
#             for e in enables:
#                 GL.glEnable(e)
# 
#             yield
#         finally:
#             GL.glPopAttrib()
# 
#     @classmethod
#     @contextmanager
#     def glEnableClientState(cls, *enables):
#         try:
#             GL.glPushClientAttrib(GL.GL_CLIENT_ALL_ATTRIB_BITS)
#             for e in enables:
#                 GL.glEnableClientState(e)
# 
#             yield
#         finally:
#             GL.glPopClientAttrib()
# 
#     listCount = 0
# 
#     @classmethod
#     def glGenLists(cls, n):
#         cls.listCount += n
#         return GL.glGenLists(n)
# 
#     @classmethod
#     def glDeleteLists(cls, base, n):
#         cls.listCount -= n
#         return GL.glDeleteLists(base, n)
# 
# Path: mceutils.py
# def loadPNGTexture(filename, *a, **kw):
#     filename = os.path.join(directories.dataDir, filename)
#     try:
#         w, h, ndata = loadPNGFile(filename)
# 
#         tex = glutils.Texture(functools.partial(loadTextureFunc, w, h, ndata), *a, **kw)
#         tex.data = ndata
#         return tex
#     except Exception, e:
#         print "Exception loading ", filename, ": ", repr(e)
#         return glutils.Texture()


# Path: compass.py
import logging
from OpenGL import GL
from drawable import Drawable
from glutils import gl
from mceutils import loadPNGTexture


    @yawPitch.setter
    def yawPitch(self, value):
        self._yawPitch = value
        self.invalidate()

    def drawSelf(self):
        if self._tex is None:
            if self.small:
                filename = "compass_small.png"
            else:
                filename = "compass.png"

            self._tex = loadPNGTexture("toolicons/" + filename)#, minFilter=GL.GL_LINEAR, magFilter=GL.GL_LINEAR)

        self._tex.bind()
        size = 0.075

        with gl.glPushMatrix(GL.GL_MODELVIEW):
            GL.glLoadIdentity()

            yaw, pitch = self.yawPitch
            GL.glTranslatef(1.-size, size, 0.0)  # position on upper right corner
            GL.glRotatef(180-yaw, 0., 0., 1.)  # adjust to north
            GL.glColor3f(1., 1., 1.)

            with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY):
                GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-size, -size, 2*size, 2*size))
                GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 256, 256))


                with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D):