def drawIcon(ren, shape, color, boxx, boxy): quarter = int(BOXSIZE * 0.25) # syntactic sugar half = int(BOXSIZE * 0.5) # syntactic sugar left, top = leftTopCoordsOfBox(boxx, boxy) # get pixel coords from board coords # Draw the shapes if shape == DONUT: sdlgfx.filledCircleRGBA(ren.renderer, left + half, top + half, half - 5, *color) sdlgfx.filledCircleRGBA(ren.renderer, left + half, top + half, quarter - 5, *BGCOLOR) elif shape == SQUARE: lqrtr = left + quarter tqrtr = top + quarter sdlgfx.boxRGBA(ren.renderer, lqrtr, tqrtr, lqrtr + BOXSIZE - half, tqrtr + BOXSIZE - half, *color) elif shape == DIAMOND: pts = ((left + half, top), (left + BOXSIZE - 1, top + half), (left + half, top + BOXSIZE - 1), (left, top + half)) draw_polygon(ren.renderer, pts, color) elif shape == LINES: for i in range(0, BOXSIZE, 4): ren.draw_line((left, top + i, left + i, top), color) ren.draw_line( (left + i, top + BOXSIZE - 1, left + BOXSIZE - 1, top + i), color) elif shape == OVAL: sdlgfx.ellipseRGBA(ren.renderer, left + BOXSIZE // 2, top + quarter + half // 2, BOXSIZE // 2, half // 2, *color)
def draw_shapes(): context.clear(WHITE) sdlgfx.filledPolygonRGBA(context.renderer, xarray, yarray, ptcnt, *GREEN) sdlgfx.filledCircleRGBA(context.renderer, 300, 50, 20, *BLUE) sdlgfx.ellipseRGBA(context.renderer, 320, 240, 20, 40, *RED) sdlgfx.boxRGBA(context.renderer, 200, 150, 300, 200, *RED) sdlgfx.thickLineRGBA(context.renderer, 60, 60, 120, 60, 4, *BLUE) sdlgfx.lineRGBA(context.renderer, 120, 60, 60, 120, *BLUE) sdlgfx.thickLineRGBA(context.renderer, 60, 120, 120, 120, 4, *BLUE) points = [380, 280, 382, 282, 384, 284, 386, 286, 388, 288] context.draw_point(points, BLACK)
def raw_aabb_solid(self, aabb, color): Y = self.height R, G, B, A = color if gfx.boxRGBA(self._renderer, trunc(aabb.xmin), trunc(Y - aabb.ymax), trunc(aabb.xmax), trunc(Y - aabb.ymin), R, G, B, A) != 0: self._sdl_error()
def raw_aabb_solid(self, aabb, color): Y = self.height R, G, B, A = color if gfx.boxRGBA( self._renderer, trunc(aabb.xmin), trunc(Y - aabb.ymax), trunc(aabb.xmax), trunc(Y - aabb.ymin), R, G, B, A) != 0: self._sdl_error()
def drawIcon(ren, shape, color, boxx, boxy): quarter = int(BOXSIZE * 0.25) # syntactic sugar half = int(BOXSIZE * 0.5) # syntactic sugar left, top = leftTopCoordsOfBox(boxx, boxy) # get pixel coords from board coords # Draw the shapes if shape == DONUT: sdlgfx.filledCircleRGBA(ren.renderer, left+half, top+half, half-5, *color) sdlgfx.filledCircleRGBA(ren.renderer, left+half, top+half, quarter-5, *BGCOLOR) elif shape == SQUARE: lqrtr = left+quarter tqrtr = top+quarter sdlgfx.boxRGBA(ren.renderer, lqrtr, tqrtr, lqrtr+BOXSIZE-half, tqrtr+BOXSIZE-half, *color) elif shape == DIAMOND: pts = ((left + half, top), (left + BOXSIZE - 1, top + half), (left + half, top + BOXSIZE - 1), (left, top + half)) draw_polygon(ren.renderer, pts, color) elif shape == LINES: for i in range(0, BOXSIZE, 4): ren.draw_line((left, top+i, left+i, top), color) ren.draw_line((left+i, top+BOXSIZE-1, left+BOXSIZE-1, top+i), color) elif shape == OVAL: sdlgfx.ellipseRGBA(ren.renderer, left+BOXSIZE//2, top+quarter+half//2, BOXSIZE//2, half//2, *color)
def clear_background(self, color=None): renderer = self._renderer sdl2.SDL_RenderClear(renderer) ret = 0 if color is None and self._bg_color is not None: ret = gfx.boxColor(renderer, 0, self.height, self.width, 0, self._bg_color) else: R, G, B, A = Color(color) ret = gfx.boxRGBA(renderer, 0, self.height, self.width, 0, R, G, B, A) if ret != 0: msg = sdl2.SDL_GetError() raise RuntimeError("SDL error: %s" % msg)
def draw(self, renderer, rect): if self.env.border and self.env.border_color and self.env.background and self.env.background.a == 255: adjusted = self.frame # + self.env.border rgba = (self.env.border_color.r, self.env.border_color.g, self.env.border_color.b, self.env.border_color.a) if self.env.radius: roundedBoxRGBA(renderer, adjusted.left, adjusted.top, adjusted.right, adjusted.bottom, self.env.radius, *rgba) else: boxRGBA(renderer, adjusted.left, adjusted.top, adjusted.right, adjusted.bottom, *rgba) if self.env.background: adjusted = self.frame - self.env.border rgba = (self.env.background.r, self.env.background.g, self.env.background.b, self.env.background.a) if self.env.radius: roundedBoxRGBA(renderer, adjusted.left, adjusted.top, adjusted.right, adjusted.bottom, self.env.radius, *rgba) else: boxRGBA(renderer, adjusted.left, adjusted.top, adjusted.right, adjusted.bottom, *rgba)
def clear_background(self, color=None): renderer = self._renderer sdl2.SDL_RenderClear(renderer) ret = 0 if color is None and self._bg_color is not None: ret = gfx.boxColor(renderer, 0, self.height, self.width, 0, self._bg_color) else: R, G, B, A = Color(color) ret = gfx.boxRGBA(renderer, 0, self.height, self.width, 0, R, G, B, A) if ret != 0: msg = sdl2.SDL_GetError() raise RuntimeError('SDL error: %s' % msg)
def render(self, xy): boxRGBA( window.renderer.sdlrenderer, xy[0], xy[1], xy[0] + self.size[0], xy[1] + self.size[1], self.color.rgba[0], self.color.rgba[1], self.color.rgba[2], self.color.rgba[3] )
def draw_button1(renderer, rect, rad, color): """...""" c = sdl2.ext.Color(*color) r, g, b, a = c.r, c.g, c.g, c.a x1 = rect.right y1 = rect.top x2 = rect.left y2 = rect.bottom cx = 0 cy = rad cx = 0 cy = rad ocx = None ocy = None df = 1 - rad d_e = 3 d_se = -2 * rad + 5 # Test for special cases of straight lines or single point # Swap x1, x2 if required if (x1 > x2): x1, x2 = x2, x1 # Swap y1, y2 if required if (y1 > y2): y1, y2 = y2, y1 # Calculate width & height w = x2 - x1 + 1 h = y2 - y1 + 1 # Maybe adjust radius r2 = rad + rad if (r2 > w): rad = w // 2 r2 = rad + rad if (r2 > h): rad = h // 2 # Setup filled circle drawing for corners x = x1 + rad y = y1 + rad dx = x2 - x1 - rad - rad dy = y2 - y1 - rad - rad # Draw corners while cx < cy: xpcx = x + cx xmcx = x - cx xpcy = x + cy xmcy = x - cy if (ocy != cy): if (cy > 0): ypcy = y + cy ymcy = y - cy # !!!!!!!!! sdlgfx.hlineRGBA(renderer, xmcx, xpcx + dx, ypcy + dy, r, g, b, a) sdlgfx.hlineRGBA(renderer, xmcx, xpcx + dx, ymcy, r, g, b, a) else: sdlgfx.hlineRGBA(renderer, xmcx, xpcx + dx, y, r, g, b, a) ocy = cy if (ocx != cx): if (cx != cy): if (cx > 0): ypcx = y + cx ymcx = y - cx sdlgfx.hlineRGBA(renderer, xmcy, xpcy + dx, ymcx, r, g, b, a) sdlgfx.hlineRGBA(renderer, xmcy, xpcy + dx, ypcx + dy, r, g, b, a) else: sdlgfx.hlineRGBA(renderer, xmcy, xpcy + dx, y, r, g, b, a) ocx = cx # Update if (df < 0): df += d_e d_e += 2 d_se += 2 else: df += d_se d_e += 2 d_se += 4 cy -= 1 cx += 1 # Inside if (dx > 0 and dy > 0): sdlgfx.boxRGBA(renderer, x1, y1 + rad + 1, x2, y2 - rad, r, g, b, a) sdlgfx.hlineRGBA(renderer, rad // 2, x2 - rad // 2, 0, 227, 227, 216, 23) sdlgfx.hlineRGBA(renderer, rad // 2 - 1, x2 - rad // 2 + 1, 1, 227, 227, 216, 23) sdlgfx.vlineRGBA(renderer, 0, rad // 2, y2 - rad // 2, 227, 227, 216, 23) sdlgfx.vlineRGBA(renderer, 1, rad // 2 - 1, y2 - rad // 2 + 1, 227, 227, 216, 23) sdlgfx.hlineRGBA(renderer, rad // 2 - 1, x2 - rad // 2 + 1, y2 - 1 - 1, 0, 0, 0, 47) sdlgfx.hlineRGBA(renderer, rad // 2, x2 - rad // 2, y2 - 1, 0, 0, 0, 47) sdlgfx.vlineRGBA(renderer, x2 - 1 - 1, rad // 2 - 1, y2 - rad // 2 + 1, 0, 0, 0, 47) sdlgfx.vlineRGBA(renderer, x2 - 1, rad // 2, y2 - rad // 2, 0, 0, 0, 47)