def draw_point(self, points, color=None): """Draws one or multiple points on the rendering context.""" # (x1, y1, x2, y2, ...) pcount = len(points) if (pcount % 2) != 0: raise ValueError("points does not contain a valid set of points") if pcount == 2: if color: tmp = self.color self.color = color try: x, y = points render.render_draw_point(self.renderer, x, y) finally: if color: self.color = tmp else: x = 0 ptlist = [] while x < pcount: ptlist.append(SDL_Point(points[x], points[x + 1])) x += 2 if color: tmp = self.color self.color = color try: render.render_draw_points(self.renderer, ptlist) finally: if color: self.color = tmp
def test_render_draw_point(self): points = ((-4, -3), (-4, 3), (4, -3), (0, 0), (1, 1), (10, 10), (99, 99), (4, 22), (57, 88), (45, 15), (100, 100) ) r, g, b, a = 0xAA, 0xBB, 0xCC, 0xDD w, h = 100, 100 sf = surface.create_rgb_surface(w, h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF) color = pixels.map_rgba(sf.format, r, g, b, a) renderer = render.create_software_renderer(sf) render.set_render_draw_color(renderer, r, g, b, a) for x, y in points: render.render_draw_point(renderer, x, y) render.render_present(renderer) view = pvid.PixelView(sf) for x, y in points: npx = max(x + 1, w) npy = max(y + 1, h) ppx = max(x - 1, 0) ppy = max(y - 1, 0) if x < 0 or x >= w or y < 0 or y >= h: continue self.assertEqual(hex(view[y][x]), hex(color)) if (npx, npy) not in points: self.assertNotEqual(hex(view[npy][npx]), hex(color)) if (ppx, ppy) not in points: self.assertNotEqual(hex(view[ppy][ppx]), hex(color)) render.destroy_renderer(renderer) del view surface.free_surface(sf)