| ''' | ''' | ||||
| from .display import Display | from .display import Display | ||||
| import pygame | |||||
| class NodeError(Exception): | class NodeError(Exception): | ||||
| pass | pass | ||||
| return | return | ||||
| self._ACTIVE_SURF.fill(color) | self._ACTIVE_SURF.fill(color) | ||||
| def draw_lines(points, color, thickness=1, closed=False): | |||||
| def draw_lines(self, points, color, thickness=1, closed=False): | |||||
| if not hasattr(self, "_ACTIVE_SURF"): | if not hasattr(self, "_ACTIVE_SURF"): | ||||
| return | return | ||||
| pygame.draw.lines(self._ACTIVE_SURF, color, closed, points, thickness) | pygame.draw.lines(self._ACTIVE_SURF, color, closed, points, thickness) | ||||
| def draw_rect(rect, color, thinkness=1): | |||||
| def draw_rect(self, rect, color, thickness=1): | |||||
| if not hasattr(self, "_ACTIVE_SURF"): | if not hasattr(self, "_ACTIVE_SURF"): | ||||
| return | return | ||||
| pygame.draw.rect(self._ACTIVE_SURF, color, rect, thickness) | pygame.draw.rect(self._ACTIVE_SURF, color, rect, thickness) | ||||
| def draw_ellipse(rect, color, thickness=1, fill_color=None): | |||||
| def draw_ellipse(self, rect, color, thickness=1, fill_color=None): | |||||
| if not hasattr(self, "_ACTIVE_SURF"): | if not hasattr(self, "_ACTIVE_SURF"): | ||||
| return | return | ||||
| if fill_color is not None: | if fill_color is not None: | ||||
| if thickness > 0: | if thickness > 0: | ||||
| pygame.draw.ellipse(self._ACTIVE_SURF, color, rect, thickness) | pygame.draw.ellipse(self._ACTIVE_SURF, color, rect, thickness) | ||||
| def draw_circle(pos, radius, color, thickness=1, fill_color=None): | |||||
| def draw_circle(self, pos, radius, color, thickness=1, fill_color=None): | |||||
| if not hasattr(self, "_ACTIVE_SURF"): | if not hasattr(self, "_ACTIVE_SURF"): | ||||
| return | return | ||||
| if fill_color is not None: | if fill_color is not None: | ||||
| if thickness > 0: | if thickness > 0: | ||||
| pygame.draw.circle(self._ACTIVE_SURF, color, pos, radius, thickness) | pygame.draw.circle(self._ACTIVE_SURF, color, pos, radius, thickness) | ||||
| def draw_polygon(points, color, thickness=1, fill_color=None): | |||||
| def draw_polygon(self, points, color, thickness=1, fill_color=None): | |||||
| if not hasattr(self, "_ACTIVE_SURF"): | if not hasattr(self, "_ACTIVE_SURF"): | ||||
| return | return | ||||
| if fill_color is not None: | if fill_color is not None: | ||||
| return | return | ||||
| if self._scale[0] == 1.0 and self._scale[1] == 1.0: | if self._scale[0] == 1.0 and self._scale[1] == 1.0: | ||||
| self._tsurface = None | self._tsurface = None | ||||
| return | |||||
| size = self._surface.get_size() | size = self._surface.get_size() | ||||
| nw = size[0] * self._scale[0] | nw = size[0] * self._scale[0] | ||||
| nh = 0 | nh = 0 | ||||
| else: | else: | ||||
| nh = size[1] * self._scale[1] | nh = size[1] * self._scale[1] | ||||
| self._tsurface = pygame.Surface((nw, nh), pygame.SRCALPHA, self._surface) | self._tsurface = pygame.Surface((nw, nh), pygame.SRCALPHA, self._surface) | ||||
| self._tsurface.fill(pygame.Color(0,0,0,0)) | |||||
| @property | @property | ||||
| def resolution(self): | def resolution(self): | ||||
| @property | @property | ||||
| def offset(self): | def offset(self): | ||||
| return self._offset | return self._offset | ||||
| @offset.setter(self, offset): | |||||
| @offset.setter | |||||
| def offset(self, offset): | |||||
| if not isinstance(offset, tuple): | if not isinstance(offset, tuple): | ||||
| raise TypeError("Expected a tuple") | raise TypeError("Expected a tuple") | ||||
| if len(offset) != 2: | if len(offset) != 2: | ||||
| if resolution is None: | if resolution is None: | ||||
| if dsurf is not None: | if dsurf is not None: | ||||
| self._surface = dsurf.convert_alpha() | self._surface = dsurf.convert_alpha() | ||||
| self._surface.fill(pygame.Color(0,0,0,0)) | |||||
| self._updateTransformSurface() | self._updateTransformSurface() | ||||
| else: | else: | ||||
| if not isinstance(r, tuple): | if not isinstance(r, tuple): | ||||
| self._surface = pygame.Surface(resolution, pygame.SRCALPHA, dsurf) | self._surface = pygame.Surface(resolution, pygame.SRCALPHA, dsurf) | ||||
| else: | else: | ||||
| self._surface = pygame.Surface(resolution, pygame.SRCALPHA) | self._surface = pygame.Surface(resolution, pygame.SRCALPHA) | ||||
| self._surface.fill(pygame.Color(0,0,0,0)) | |||||
| self._updateTransformSurface() | self._updateTransformSurface() | ||||
| def _render(self, surface): | def _render(self, surface): | ||||
| if self._tsurface is not None: | if self._tsurface is not None: | ||||
| pygame.transform.scale(self._surface, self._tsurface.get_size(), self._tsurface) | pygame.transform.scale(self._surface, self._tsurface.get_size(), self._tsurface) | ||||
| src = self._tsurface | src = self._tsurface | ||||
| if ssize[0] == dsize[0] and ssize[1] == dsize[1]: | |||||
| dest.blit(src, pos) | |||||
| dest.blit(src, pos) | |||||