Example #1
0
 def blit(self, surface, position, area=None):
     """
     Draw given surface on this surface at position.
     Optional area delimitates the region of given surface to draw.
     """
     ctx = self.impl.canvasContext
     ctx.globalAlpha = surface._alpha
     if not area:
         ctx.drawImage(surface.canvas, position[0], position[1])
         ctx.globalAlpha = 1.0
         if _return_rect:
             rect = rectPool.get(position[0], position[1], surface.width,
                                 surface.height)
         else:
             return None
     else:
         ctx.drawImage(surface.canvas, area[0], area[1], area[2], area[3],
                       position[0], position[1], area[2], area[3])
         ctx.globalAlpha = 1.0
         if _return_rect:
             rect = rectPool.get(position[0], position[1], area[2], area[3])
         else:
             return None
     if self._display:
         surface_rect = self._display._surface_rect
     else:
         surface_rect = self.get_rect()
     changed_rect = surface_rect.clip(rect)
     rectPool.append(rect)
     return changed_rect
Example #2
0
 def blit(self, surface, position, area=None):
     """
     Draw given surface on this surface at position.
     Optional area delimitates the region of given surface to draw.
     """
     if not _return_rect:
         if not area:
             self.impl.canvasContext.drawImage(surface.canvas, position[0],
                                               position[1])
         else:
             self.impl.canvasContext.drawImage(surface.canvas, area[0],
                                               area[1], area[2], area[3],
                                               position[0], position[1],
                                               area[2], area[3])
             return None
     if not area:
         rect = rectPool.get(position[0], position[1], surface.width,
                             surface.height)
         self.impl.canvasContext.drawImage(surface.canvas, rect.x, rect.y)
     else:
         rect = rectPool.get(position[0], position[1], area[2], area[3])
         self.impl.canvasContext.drawImage(surface.canvas, area[0], area[1],
                                           area[2], area[3], rect.x, rect.y,
                                           area[2], area[3])
     if self._display:
         surface_rect = self._display._surface_rect
     else:
         surface_rect = self.get_rect()
     changed_rect = surface_rect.clip(rect)
     rectPool.append(rect)
     return changed_rect
Example #3
0
 def blits(self, blit_sequence, doreturn=True):
     """
     Draw a sequence of surfaces on this surface.
     Argument blit_sequence of (source, dest) or (source, dest, area).
     Optional doreturn (defaults to True) to return list of rects.
     """
     ctx = self.impl.canvasContext
     if doreturn:
         rects = []
         if self._display:
             surface_rect = self._display._surface_rect
         else:
             surface_rect = self.get_rect()
     else:
         rects = None
     for blit in blit_sequence:
         surface = blit[0]
         position = blit[1]
         if not position._width:
             x = position[0]
             y = position[1]
         else:
             x = position.x
             y = position.y
         if len(blit) > 2:
             area = blit[2]
             if not area._width:
                 ax = area[0]
                 ay = area[1]
                 aw = area[2]
                 ah = area[3]
             else:
                 ax = area.x
                 ay = area.y
                 aw = area.width
                 ah = area.height
         else:
             area = None
         ctx.globalAlpha = surface._alpha
         if not area:
             ctx.drawImage(surface.canvas, x, y)
             if doreturn:
                 rect = rectPool.get(x, y, surface.width, surface.height)
                 rects.append(surface_rect.clip(rect))
                 rectPool.append(rect)
         else:
             ctx.drawImage(surface.canvas, ax, ay, aw, ah, x, y, aw, ah)
             if doreturn:
                 rect = rectPool.get(x, y, aw, ah)
                 rects.append(surface_rect.clip(rect))
                 rectPool.append(rect)
     ctx.globalAlpha = 1.0
     return rects
Example #4
0
 def __call__(self, sprite1, sprite2):   #__call__ not implemented in pyjs
     r = sprite1.rect
     x = (r.width*self.ratio)-r.width
     y = (r.height*self.ratio)-r.height
     r1 = rectPool.get(r.x-int(x*0.5), r.y-int(y*0.5), r.width+int(x), r.height+int(y))
     r = sprite2.rect
     x = (r.width*self.ratio)-r.width
     y = (r.height*self.ratio)-r.height
     r2 = rectPool.get(r.x-int(x*0.5), r.y-int(y*0.5), r.width+int(x), r.height+int(y))
     collide = r1.intersects(r2)
     rectPool.extend((r1,r2))
     return collide
Example #5
0
 def __call__(self, sprite1, sprite2):   #__call__ not implemented in pyjs
     r = sprite1.rect
     x = (r.width*self.ratio)-r.width
     y = (r.height*self.ratio)-r.height
     r1 = rectPool.get(r.x-int(x*0.5), r.y-int(y*0.5), r.width+int(x), r.height+int(y))
     r = sprite2.rect
     x = (r.width*self.ratio)-r.width
     y = (r.height*self.ratio)-r.height
     r2 = rectPool.get(r.x-int(x*0.5), r.y-int(y*0.5), r.width+int(x), r.height+int(y))
     collide = r1.intersects(r2)
     rectPool.extend((r1,r2))
     return collide
Example #6
0
 def __call__(self, sprite1, sprite2):  #__call__ not implemented in pyjs
     r = sprite1.rect
     x = (r.width * self.ratio) - r.width
     y = (r.height * self.ratio) - r.height
     rect1 = rectPool.get(r.x - int(x * 0.5), r.y - int(y * 0.5),
                          r.width + int(x), r.height + int(y))
     r = sprite2.rect
     x = (r.width * self.ratio) - r.width
     y = (r.height * self.ratio) - r.height
     rect2 = rectPool.get(r.x - int(x * 0.5), r.y - int(y * 0.5),
                          r.width + int(x), r.height + int(y))
     collide = (rect1._x < (rect2._x + rect2._width) and rect2._x <
                (rect1._x + rect1._width) and rect1._y <
                (rect2._y + rect2._height) and rect2._y <
                (rect1._y + rect1._height))
     rectPool.append(r1)
     rectPool.append(r2)
     return collide
Example #7
0
 def blit(self, surface, position, area=None):
     """
     Draw given surface on this surface at position.
     Optional area delimitates the region of given surface to draw.
     """
     if not area:
         rect = rectPool.get(position[0],position[1],surface.width,surface.height)
         self.impl.canvasContext.drawImage(surface.canvas, rect.x, rect.y)
     else:
         rect = rectPool.get(position[0],position[1],area[2], area[3])
         self.impl.canvasContext.drawImage(surface.canvas, area[0], area[1], area[2], area[3], rect.x, rect.y, area[2], area[3])
     if self._display:
         surface_rect = self._display._surface_rect
     else:
         surface_rect = self.get_rect()
     changed_rect = surface_rect.clip(rect)
     rectPool.append(rect)
     return changed_rect
Example #8
0
 def blit(self, surface, position, area=None):
     """
     Draw given surface on this surface at position.
     Optional area delimitates the region of given surface to draw.
     """
     if not position._width:
         x = position[0]
         y = position[1]
     else:
         x = position.x
         y = position.y
     ctx = self.impl.canvasContext
     ctx.globalAlpha = surface._alpha
     if not area:
         ctx.drawImage(surface.canvas, x, y)
         ctx.globalAlpha = 1.0
         if _return_rect:
             rect = rectPool.get(x, y, surface.width, surface.height)
         else:
             return None
     else:
         if not area._width:
             ax = area[0]
             ay = area[1]
             aw = area[2]
             ah = area[3]
         else:
             ax = area.x
             ay = area.y
             aw = area.width
             ah = area.height
         ctx.drawImage(surface.canvas, ax, ay, aw, ah, x, y, aw, ah)
         ctx.globalAlpha = 1.0
         if _return_rect:
             rect = rectPool.get(x, y, aw, ah)
         else:
             return None
     if self._display:
         surface_rect = self._display._surface_rect
     else:
         surface_rect = self.get_rect()
     changed_rect = surface_rect.clip(rect)
     rectPool.append(rect)
     return changed_rect
Example #9
0
 def fill(self, color=None, rect=None):
     """
     Fill surface with color.
     """
     if color is None:
         HTML5Canvas.fill(self)
         return None
     if self._fill_style != color:
         self._fill_style = color
         if hasattr(color, 'a'):
             self.setFillStyle(color)
         else:
             self.setFillStyle(Color(color))
     if not _return_rect:
         if rect is None:
             self.fillRect(0, 0, self.width, self.height)
         else:
             self.fillRect(rect[0], rect[1], rect[2], rect[3])
         return None
     if rect is None:
         _rect = Rect(0, 0, self.width, self.height)
         self.fillRect(_rect.x, _rect.y, _rect.width, _rect.height)
     else:
         if self._display:
             if hasattr(rect, 'width'):
                 _rect = self._display._surface_rect.clip(rect)
             else:
                 _rect_ = rectPool.get(rect[0], rect[1], rect[2], rect[3])
                 _rect = self._display._surface_rect.clip(_rect_)
                 rectPool.append(_rect_)
         else:
             surface_rect = rectPool.get(0, 0, self.width, self.height)
             if hasattr(rect, 'width'):
                 _rect = surface_rect.clip(rect)
             else:
                 _rect_ = rectPool.get(rect[0], rect[1], rect[2], rect[3])
                 _rect = surface_rect.clip(_rect_)
                 rectPool.append(_rect_)
             rectPool.append(surface_rect)
         if _rect.width and _rect.height:
             self.fillRect(_rect.x, _rect.y, _rect.width, _rect.height)
     return _rect
Example #10
0
 def blits(self, blit_sequence, doreturn=True):
     """
     Draw a sequence of surfaces on this surface.
     Argument blit_sequence of (source, dest) or (source, dest, area).
     Optional doreturn (defaults to True) to return list of rects.
     """
     ctx = self.impl.canvasContext
     if doreturn:
         rects = []
         if self._display:
             surface_rect = self._display._surface_rect
         else:
             surface_rect = self.get_rect()
     else:
         rects = None
     for blit in blit_sequence:
         surface = blit[0]
         position = blit[1]
         if len(blit) > 2:
             area = blit[2]
         else:
             area = None
         ctx.globalAlpha = surface._alpha
         if not area:
             ctx.drawImage(surface.canvas, position[0], position[1])
             if doreturn:
                 rect = rectPool.get(position[0], position[1],
                                     surface.width, surface.height)
                 rects.append(surface_rect.clip(rect))
                 rectPool.append(rect)
         else:
             ctx.drawImage(surface.canvas, area[0], area[1], area[2],
                           area[3], position[0], position[1], area[2],
                           area[3])
             if doreturn:
                 rect = rectPool.get(position[0], position[1], area[2],
                                     area[3])
                 rects.append(surface_rect.clip(rect))
                 rectPool.append(rect)
     ctx.globalAlpha = 1.0
     return rects