def resize(self, width, height): """ Resize surface. """ self.width = int(width) self.height = int(height) HTML5Canvas.resize(self, self.width, self.height)
def fill(self, color=None, rect=None): """ Fill surface with color. """ if color is None: HTML5Canvas.fill(self) return if color: if self._fill_style != color: self._fill_style = color if hasattr(color, 'a'): self.setFillStyle(color) else: self.setFillStyle(Color(color)) if not rect: _rect = Rect(0, 0, self.width, self.height) else: if self._display: surface_rect = self._display._surface_rect else: surface_rect = self.get_rect() if hasattr(rect, 'width'): _rect = surface_rect.clip( rect ) else: _rect = surface_rect.clip( Rect(rect) ) if not _rect.width or not _rect.height: return _rect self.fillRect(_rect.x, _rect.y, _rect.width, _rect.height) else: _rect = Rect(0, 0, self.width, self.height) self.clear() return _rect
def __init__(self, size, *args, **kwargs): """ Return Surface subclassed from a Canvas implementation. The size argument is the dimension (w,h) of surface. Module initialization places pyjsdl.Surface in module's namespace. """ self.width = int(size[0]) self.height = int(size[1]) HTML5Canvas.__init__(self, self.width, self.height) HTML5Canvas.resize(self, self.width, self.height) self._display = None #display surface self._super_surface = None self._offset = (0,0) self._colorkey = None self._nonimplemented_methods()
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
def init(): """ **pyjsdl.font.init** Initialize font module. """ global _surf, _initialized, match_font if _initialized: return try: _surf = HTML5Canvas(1, 1) _surf.measureText('x') except: _surf = None _initialized = True
def resize(self, width, height): self.width = int(width) self.height = int(height) HTML5Canvas.resize(self, self.width, self.height)