title: Python pygame Detect if mouse is over non transparent part of surface
body: <p>I am trying to make a UI for my game and there are some curves to the UI. Now I can detect collision between two surfaces. I can detect by pixel between two sprites, but it seems mouse detection by pixel is alluding me. Basically I want to detect when the mouse is over the UI and then ignore everything below that while getting the UI.</p>
  
  <p>This is a picture of what I have so far. If you notice the pink square the mouse is over the GUI while the yellow selector box is over a tile. The yellow selector is a box frame over a tile.</p>
  
  <p>I am using pygame with openGL but at this point I am looking for ANY solution to this. I can adapt pretty easily as I am not new to programming and pretty much looking for any solution.
  Also I would post the code but to much code to post so if thing specific is needed let me know.</p>
  
  <p>One thing to note is that the GUI is flexable in that the upper left area will slide in and out. Also the white is just placeholder so final colors are not used and would be difficult to check. Is it possible to get the surface elements under the mouse when clicked by z order?</p>
  
  <p><strong>Texture</strong></p>
  
  <pre><code>import pygame
  from OpenGL.GL import *
  from OpenGL.GLU import *
  
  class Texture(object):
      image = None
      rect = None
      src = ''
      x = 0
      y = 0
      '''
      zOrder Layers
      0  - background
      1  - 
      2  - 
      3  - Tile Selector
      s  - Tiles
      5  - 
      6  - 
      7  - Panels
      8  - Main Menu
      9  - GUI Buttons
      10 - 
  
      '''
  
      def __init__(self, src):
          self.src = src
          self.image = pygame.image.load(src)
          self.image.set_colorkey(pygame.Color(255,0,255,0))
          self.rect = self.image.get_rect()
          texdata = pygame.image.tostring(self.image,"RGBA",0)
          # create an object textures
          self.texid = glGenTextures(1)
  
          # bind object textures 
          glBindTexture(GL_TEXTURE_2D, self.texid)
  
          # set texture filters
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  
          # Create texture image
          glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,self.rect.w,self.rect.h,0,GL_RGBA,GL_UNSIGNED_BYTE,texdata)
  
  
          self.newList = glGenLists(2)
          glNewList(self.newList, GL_COMPILE)
          glBindTexture(GL_TEXTURE_2D, self.texid)
          glBegin(GL_QUADS)
          glTexCoord2f(0, 0); glVertex3f(0, 0 ,0)
          glTexCoord2f(0, 1); glVertex3f(0, self.rect.h, 0)
          glTexCoord2f(1, 1); glVertex3f(self.rect.w, self.rect.h, 0)
          glTexCoord2f(1, 0); glVertex3f(self.rect.w, 0, 0)
  
          glEnd()
          glEndList()
  
      def getImg(self):
          return self.image
  
      def getPos(self):
          rect = self.getImg().get_rect()
          pos = dict(x=self.x,y=self.y,w=rect[2],h=rect[3])
          return pos
  
      def draw(self,x,y,rotate=0):
          glLoadIdentity()
          self.x = int(x)
          self.y = int(y-self.rect.h+32)
  
          glTranslatef(x,y-self.rect.h+32,0)
  
          glPushAttrib(GL_TRANSFORM_BIT)
          glMatrixMode(GL_TEXTURE)
          glLoadIdentity()
          glRotatef(rotate,0,0,1)
          glPopAttrib()
  
          if glIsList(self.newList):
              glCallList(self.newList)
  </code></pre>
  
  <p><strong>gui Class</strong></p>
  
  <pre><code>import hashlib, string, pygame
  from classes.texture import Texture
  
  '''
  Created on Jun 2, 2013
  
  @author: Joel
  '''
  
  class gui(object):
      INSTANCES = 0           # Count of instances of buildings
      ID = 0                  # Building ID
      TYPE = 0                # Building type
      NAME = ''               # name of Building
      DESCRIPTION = ''        # Description of building
      IMAGE = ''              # Image name of building 
  
      zOrder = 0
      clickable = True
  
      def __init__(self, Game, name = 'Building', description = '', image = 'panel'):
          self.INSTANCES += 1
          self.setName(name)
          self.setDescription(description)
          self.setImage(Game, Game.SETTING["DIR"]["IMAGES"] + Game.SETTING["THEME"] + '\\gui\\'+image+'.png')
          self.setType(name.lower())
          self.setZ(6)
  
      def getDescription(self):
          return self.DESCRIPTION
  
      def setDescription(self, description):
          self.DESCRIPTION = description
  
      def getID(self):
          return self.ID
  
      def setID(self, i):
          allchr = string.maketrans('','')
          nodigits = allchr.translate(allchr, string.digits)
          s = hashlib.sha224(i).hexdigest()
          s = s.translate(allchr, nodigits)
          self.ID = s[-16:]
  
      def getImage(self):
          return self.IMAGE
  
      def setImage(self, Game, i):
          self.IMAGE = Texture(Game.CWD + '\\' + i)
  
      def getName(self):
          return self.NAME
  
      def setName(self, name):
          self.NAME = name
  
      def getType(self):
          return self.TYPE
  
      def setType(self, t):
          self.TYPE = t
  
      def click(self, x, y):
          if pygame.mouse.get_pressed()[0] == 1:
              if x &gt; self.x and x &lt; (self.x + self.rect.w):
                  if y &gt; self.y and y &lt; (self.y + self.rect.h):
                      print("Clicked: " + str(self.x) + ', ' + str(self.y) + ', ' + str(self.rect.w) + ', ' + str(self.rect.y))
  
      def getClickable(self):
          return self.clickable
  
      def setClickable(self, c):
          self.clickable = c
  
      def getZ(self):
          return self.zOrder
  
      def setZ(self, z):
          self.zOrder = z
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/7sq7Z.png" alt="pygame"></p>