Example #1
0
def get_circle(color, radius, graphics, blur = 0):
    global circle_cache, circle_cache_hit, circle_cache_miss
    # color accuracy
    c = tuple()
    for i in xrange(4):
      colval = int(color[i] / 8 + 0.5) * 8
      if colval > 255: colval = 255
      c += (colval,)
    color  = tuple(c)
    radius = int(radius)
    blur   = int(blur)

    # try to get it from cache
    if circle_cache.has_key((color, radius, blur)):
      circle_cache_hit += 1
      return circle_cache[(color, radius, blur)]
    else:
      circle_cache_miss += 1
      s = pygame.surface.Surface((radius * 2, radius * 2), pygame.SRCALPHA, 32)
      # 0-alpha background
      s.fill(color[:3] + (0,))
      # circle
      pygame.draw.circle(s, color, (radius, radius), radius, 0)

      # blur the edges of the circle (just set the alpha)
      if blur:
        alphas      = pygame.surfarray.pixels_alpha(s)
        color_alpha = color[3]
        center      = radius
        for y in xrange(radius):
          for x in xrange(radius):
            if x + y < radius - blur:
              pass
            dist = ((x - center) ** 2 + (y - center) ** 2) ** 0.5
            if dist < radius - blur:
              pass
            elif dist > radius + 0.5:
              pass
            else:
              alpha = max(radius - dist, 0.0) / (blur + 1) * color_alpha
              alphas[y][x] = alpha
              alphas[2 * center - 1 - y][x] = alpha
              alphas[y][2 * center - 1 - x] = alpha
              alphas[2 * center - 1 - y][2 * center - 1 - x] = alpha

      # optimize for screen
      if graphics and graphics.screen:
        s = s.convert_alpha(graphics.screen)
      s = graphics.image(s)

      # save to cache
      circle_cache[(color, radius, blur)] = s
      return s
Example #2
0
 def _AddFormToImageList(self, form, icon_size, icon_disabled):
     wx_image = graphics.image(form.icon, icon_size)
     form.icon_bitmap = wx.BitmapFromImage(wx_image)
     # rescale(image, icon_size[0], icon_size[1])
     import Image
     from wxPil import pil_wxImage, wxImage_pil
     wx_image = pil_wxImage(wxImage_pil(wx_image).resize(icon_size,\
                                                     Image.ANTIALIAS))
     form.icon_tree = wx.BitmapFromImage(wx_image)
     form.icon_tree_disabled = icon_disabled
     form.icon_tree_id = (self.image_list.Add(form.icon_tree_disabled),
                          self.image_list.Add(form.icon_tree))
Example #3
0
 def _AddFormToImageList(self, form, icon_size, icon_disabled):
     wx_image = graphics.image(form.icon, icon_size)
     form.icon_bitmap = wx.BitmapFromImage(wx_image)
     # rescale(image, icon_size[0], icon_size[1])
     from PIL import Image
     from wxPil import pil_wxImage, wxImage_pil
     wx_image = pil_wxImage(wxImage_pil(wx_image).resize(icon_size,\
                                                     Image.ANTIALIAS))
     form.icon_tree = wx.BitmapFromImage(wx_image)
     form.icon_tree_disabled = icon_disabled
     form.icon_tree_id = (
         self.image_list.Add(form.icon_tree_disabled),
         self.image_list.Add(form.icon_tree))