def fill_canvas(self): super(FilledLineDiagramElementsContainer, self).fill_canvas() from kivy.graphics.vertex_instructions import Quad self.quads = [] with self.canvas.before: self.quads = [Quad() for i in range(len(self.values) - 1)]
def init_tiles(self): self.tiles_quad.clear() self.tiles_coordinates.clear() with self.canvas: Color(1, 1, 1) for i in range(0, NBR_INIT_TILES): # Color(1 - t / 5, 1 - t / 10, 1 - t / 20) self.tiles_quad.append( Quad(points=[0, 0, 0, 0, 0, 0, 0, 0] )) # TODO ... ajouter unlabel avec n° ... ?! How to !? self.tiles_coordinates.append((0, i)) print(f"init_tiles -> nbr. of tiles/quad={len(self.tiles_quad)}")
def update_tiles(self, y_path_step): # quads and tiles_coordinates must be the same quantity diff_nbr = len(self.tiles_coordinates) - len(self.tiles_quad) if diff_nbr > 0: #print(f"DEBUG - update_tiles : diff_nbr={diff_nbr}") for i in range(0, diff_nbr): self.tiles_quad.append(Quad()) # add quad if diff_nbr < 0: #print(f"DEBUG - update_tiles : diff_nbr={diff_nbr}") for i in range(0, abs(diff_nbr)): self.tiles_quad.pop(-1) # remove quad # update tiles for i, tq in enumerate(self.tiles_quad, start=0): tc = self.tiles_coordinates[i] # Retrieve indexes of vertical and horizontal lines line_v_min = int(self.V_NBR_LINES * 0.5 - 1) + tc[0] line_h_min = tc[1] - y_path_step # i.e. score = y_path_step line_v_max = line_v_min + 1 line_h_max = line_h_min + 1 # Check and limit computation within grid boundaries if line_h_max < self.H_NBR_LINES and line_v_max < self.V_NBR_LINES and line_h_min >= 0 and line_v_min >= 0: # Compute the four corners for the quad graphic x1, y1 = self.compute_tile_point_corner(line_v_min, line_h_min) x2, y2 = self.compute_tile_point_corner(line_v_min, line_h_max) x3, y3 = self.compute_tile_point_corner(line_v_max, line_h_max) x4, y4 = self.compute_tile_point_corner(line_v_max, line_h_min) # Assign tile points to (re)build the quad graphic tq.points = [x1, y1, x2, y2, x3, y3, x4, y4] else: tq.points = [0, 0, 0, 0, 0, 0, 0, 0] if self.IS_DEBUG_ENABLE: print(f"DEBUG - update_tiles[{i}]: TOUCH BOUNDARIES") print( f"DEBUG - update_tiles[{i}]: MIN - h={line_h_min} , v={line_v_min}" ) print( f"DEBUG - update_tiles[{i}]: MAX - h={line_h_max} , v={line_v_max}" ) return # quit loop if self.IS_DEBUG_ENABLE: print( f"DEBUG - update_tiles[{i}]: all tiles coordinates={self.tiles_coordinates}" ) print(f"DEBUG - update_tiles[{i}]: tile coordinates={tc}") print( f"DEBUG - update_tiles[{i}]: lines(vmin,hmin)=({line_v_min},{line_h_min})" ) print( f"DEBUG - update_tiles[{i}]: lines(vmax,hmax)=({line_v_max},{line_h_max})" ) print(f"DEBUG - update_tiles[{i}]: tile.points={tq.points}\n")
def init_tiles(self): with self.canvas: Color(1, 1, 1) for i in range(self.NB_TILES): self.tiles.append(Quad())
def create_letter(self, letter): quads = self.quads quads.append( Quad(points=[0, 0, 0, 0, 0, 0, 0, 0], texture=self._cache[letter].texture))
def inner_draw(self): sel_r = self.selection_r * self.zoom show_selection_areas = self.action == CurrentAction.edit Color(*self.colors['grid']) for i in range(0, app.map.size[0], self.grid_step): Line(points=(i, 0, i, app.map.size[1])) for i in range(0, app.map.size[1], self.grid_step): Line(points=(0, i, app.map.size[0], i)) Color(*self.colors['finish'], 0.8) if len(app.map.finish) == 2: Rectangle(pos=app.map.finish[0], size=(app.map.finish[1][0] - app.map.finish[0][0], app.map.finish[1][1] - app.map.finish[0][1])) if show_selection_areas: Color(*self.colors['finish'], 0.3) for point in app.map.finish: Ellipse(pos=(point[0] - sel_r, point[1] - sel_r), size=(sel_r * 2, sel_r * 2)) Color(*self.colors['wall']) Line(rectangle=(0, 0, app.map.size[0], app.map.size[1])) for wall in app.map.walls: for i in range(len(wall) - 1): Line(points=(wall[i][0], wall[i][1], wall[i + 1][0], wall[i + 1][1])) if show_selection_areas: Color(*self.colors['wall'], 0.3) for wall in app.map.walls: for point in wall: Ellipse(pos=(point[0] - sel_r, point[1] - sel_r), size=(sel_r * 2, sel_r * 2)) Color(*self.colors['main_line']) for i in range(len(app.map.headline) - 1): Line(points=( app.map.headline[i][0], app.map.headline[i][1], app.map.headline[i + 1][0], app.map.headline[i + 1][1])) if show_selection_areas: Color(*self.colors['main_line'], 0.3) for point in app.map.headline: Ellipse(pos=(point[0] - sel_r, point[1] - sel_r), size=(sel_r * 2, sel_r * 2)) Color(*self.colors['selected_car']) sz = app.map.car_size for x, y, a in app.map.cars: Quad(points=( x + sz[0] * math.cos(a) - sz[1] * math.sin(a), y - sz[0] * math.sin(a) - sz[1] * math.cos(a), x - sz[0] * math.cos(a) - sz[1] * math.sin(a), y + sz[0] * math.sin(a) - sz[1] * math.cos(a), x - sz[0] * math.cos(a) + sz[1] * math.sin(a), y + sz[0] * math.sin(a) + sz[1] * math.cos(a), x + sz[0] * math.cos(a) + sz[1] * math.sin(a), y - sz[0] * math.sin(a) + sz[1] * math.cos(a)) ) Color(*self.colors['bg'], 0.5) for x, y, a in app.map.cars: Ellipse(pos=(x - sz[1] * math.sin(a) / 2 - 0.15, y - sz[1] * math.cos(a) / 2 - 0.15), size=(0.3, 0.3)) if self.action == CurrentAction.edit and self.sel is not None: def draw_selected_point(point, color): Color(*color, 0.5) Ellipse(pos=(point[0] - sel_r, point[1] - sel_r), size=(sel_r * 2, sel_r * 2)) Color(*self.colors['selection'], 1) Line(ellipse=(point[0] - sel_r, point[1] - sel_r, sel_r * 2, sel_r * 2)) if self.sel[0] == 'wall': draw_selected_point(app.map.walls[self.sel[1]][self.sel[2]], self.colors['wall']) if self.sel[0] == 'headline': draw_selected_point(app.map.headline[self.sel[1]], self.colors['main_line']) if self.sel[0] == 'finish': draw_selected_point(app.map.finish[self.sel[1]], self.colors['finish']) if self.sel[0] == 'car': x, y, a = app.map.cars[self.sel[1]] Color(*self.colors['selection'], 1) Line(points=( x + sz[0] * math.cos(a) - sz[1] * math.sin(a), y - sz[0] * math.sin(a) - sz[1] * math.cos(a), x - sz[0] * math.cos(a) - sz[1] * math.sin(a), y + sz[0] * math.sin(a) - sz[1] * math.cos(a), x - sz[0] * math.cos(a) + sz[1] * math.sin(a), y + sz[0] * math.sin(a) + sz[1] * math.cos(a), x + sz[0] * math.cos(a) + sz[1] * math.sin(a), y - sz[0] * math.sin(a) + sz[1] * math.cos(a)), width=1.3 * self.zoom, close=True )